From df488237d457eeffbe5c8281b1c19a8e9c5de596 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 17 Mar 2018 01:30:47 +0545 Subject: [PATCH] core: fix race in PidfulStreamHandler Need to re-test with the lock held, else >1 threads can end up waiting for lock then reopening the log repeatedly. --- mitogen/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mitogen/core.py b/mitogen/core.py index 151d19d8..3a56971a 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -219,6 +219,8 @@ class PidfulStreamHandler(logging.StreamHandler): def _reopen(self): self.acquire() try: + if self.open_pid == os.getpid(): + return ts = time.strftime('%Y%m%d_%H%M%S') path = self.template % (os.getpid(), ts) self.stream = open(path, 'w', 1)