changeset 7fb4e67c64be in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=7fb4e67c64be
description:
        Ensure one status thread is started per process

        issue10335
        review349751004
diffstat:

 trytond/status.py |  14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diffs (34 lines):

diff -r 5ba16bdb2a1c -r 7fb4e67c64be trytond/status.py
--- a/trytond/status.py Tue Apr 27 10:38:24 2021 +0200
+++ b/trytond/status.py Wed Apr 28 00:33:38 2021 +0200
@@ -15,9 +15,14 @@
 
 Process = namedtuple('Process', ['start_time', 'request'])
 
+_PID = None
+_PATH = None
+_LOCK = threading.Lock()
+
 
 @contextmanager
 def processing(request):
+    start(_PATH)  # check if running thread
     process = Process(time.perf_counter(), request)
     status[id(process)] = process
     try:
@@ -67,7 +72,14 @@
 
 
 def start(path):
-    threading.Thread(target=dumper, args=(path,), daemon=True).start()
+    global _PID, _PATH
+    if _PID != os.getpid() and path:  # Quick test without lock
+        with _LOCK:
+            if _PID != os.getpid():
+                threading.Thread(
+                    target=dumper, args=(path,), daemon=True).start()
+                _PID = os.getpid()
+                _PATH = path
 
 
 def listen(path, callback=None):

Reply via email to