Mercurial > hg > orthanc-book
changeset 591:2397b0e12bc8
solution to avoid deadlock in Python OnChange()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 Jan 2021 14:53:36 +0100 |
parents | 404aca6160f0 |
children | 63d8db5978c9 |
files | Sphinx/source/plugins/python.rst |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 .......................................