From 95b1d4cf125b677286c871d88efaf18152522754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 28 Apr 2021 00:33:38 +0200 Subject: [PATCH] Ensure one status thread is started per process issue10335 review349751004 --- trytond/status.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/trytond/status.py b/trytond/status.py index 4d3db5453e..36e3533e4f 100644 --- a/trytond/status.py +++ b/trytond/status.py @@ -15,9 +15,14 @@ address = 'trytond-stat.socket' 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 dumper(path): 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):