Hi, thanks for maintaining modbus_tk.
I'm trying to understand the intended use of the threadsafe argument on Master.execute() and the process-global RLock in modbus_tk/utils.py.
My setup:
- Multiple
Master instances (TCP and RTU), each owning a separate physical link.
- Each
Master is only ever called from a single dedicated IO thread — no Master is shared between threads.
- With ~6–7 concurrent
Master instances, threads serialise behind the global RLock in execute(), causing dropouts on unrelated devices.
Questions:
- Is the
RLock in utils.threadsafe_function intended to protect a single Master/socket from concurrent access, or is there shared global state across Master instances that it's also guarding?
- If each
Master is confined to one thread (i.e. the socket/serial handle is never touched concurrently), is it safe to pass threadsafe=False to execute()? Are there any known failure modes — e.g. shared buffers, transaction ID generation, or logging — that could still cause frame interleaving or corruption?
- Has there been any consideration of making the lock per-
Master rather than process-global? Happy to contribute a PR if that direction is welcome.
For context: we're hitting this in a real-time industrial control loop where lock contention on one link causes timing failures on others, so getting this right (rather than just patching it out) matters to us.
Thanks!
Hi, thanks for maintaining
modbus_tk.I'm trying to understand the intended use of the
threadsafeargument onMaster.execute()and the process-globalRLockinmodbus_tk/utils.py.My setup:
Masterinstances (TCP and RTU), each owning a separate physical link.Masteris only ever called from a single dedicated IO thread — noMasteris shared between threads.Masterinstances, threads serialise behind the globalRLockinexecute(), causing dropouts on unrelated devices.Questions:
RLockinutils.threadsafe_functionintended to protect a singleMaster/socket from concurrent access, or is there shared global state acrossMasterinstances that it's also guarding?Masteris confined to one thread (i.e. the socket/serial handle is never touched concurrently), is it safe to passthreadsafe=Falsetoexecute()? Are there any known failure modes — e.g. shared buffers, transaction ID generation, or logging — that could still cause frame interleaving or corruption?Masterrather than process-global? Happy to contribute a PR if that direction is welcome.For context: we're hitting this in a real-time industrial control loop where lock contention on one link causes timing failures on others, so getting this right (rather than just patching it out) matters to us.
Thanks!