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):