modbus-tk icon indicating copy to clipboard operation
modbus-tk copied to clipboard

Use of RLocks

Open desowin opened this issue 7 years ago • 1 comments

Up to Python 3.1, RLocks are implemented in Python and hence are slower than Locks.

There are 4 places in modbus_tk where RLock is used. Regarding the modbus-tk library itself, it is fine to replace them all with (non-recursive) Locks - all uses in the library are perfectly fine without recurise locks. The RLock in Databank can be changed to Lock without any discrepancy to end users.

Changing of other RLocks into Lock would introducing following discrepancies for users:

  • Registering or removing a hook from within invoked hook handler would result in deadlock
  • Functions decorated as threadsafe_function could no longer call themselves (recursion not possible)
  • It would be no longer possible to add/remove/set/get datablock values from within "modbus.Slave.handle_request", "modbus.Slave.on_handle_broadcast" and "modbus.Slave.on_exception"

What do you think about doing this change?

desowin avatar Mar 02 '18 18:03 desowin

Hello,

Thanks for all this information. Do you have any benchmark about the performance issue cause by RLocks?

Unless it appears to be significant, i would not change if it can cause side-effects. If it appears to be significant, it may be an option... but the default should be ti use RLock.

Does it make sense?

ljean avatar Apr 25 '18 13:04 ljean