Ensure one status thread is started per process

issue10335
review349751004
This commit is contained in:
Cédric Krier
2021-04-28 00:33:38 +02:00
parent f4669ab6e9
commit 95b1d4cf12
+13 -1
View File
@@ -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):