# HG changeset patch # User Sebastien Jodogne # Date 1610027616 -3600 # Node ID 2397b0e12bc82c96c144cb24cbf2b2cdff7e7bd8 # Parent 404aca6160f0e041fa330c74b53a97a61b33a672 solution to avoid deadlock in Python OnChange() diff -r 404aca6160f0 -r 2397b0e12bc8 Sphinx/source/plugins/python.rst --- a/Sphinx/source/plugins/python.rst Thu Jan 07 09:03:34 2021 +0100 +++ b/Sphinx/source/plugins/python.rst Thu Jan 07 14:53:36 2021 +0100 @@ -289,6 +289,24 @@ thread, passing the pending events to be processed through a message queue. +Here is the template of a possible solution to avoid such deadlocks by +relying on the multithreading primitives of Python:: + + import orthanc + import threading + + def OnChange(changeType, level, resource): + # One can safely invoke the "orthanc" module in this function + orthanc.LogWarning("Hello world") + + def _OnChange(changeType, level, resource): + # Invoke the actual "OnChange()" function in a separate thread + t = threading.Timer(0, function = OnChange, args = (changeType, level, resource)) + t.start() + + orthanc.RegisterOnChangeCallback(_OnChange) + + Accessing the content of a new instance .......................................