Ensure one status thread is started per process
issue10335 review349751004
This commit is contained in:
+13
-1
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user