[Zconfig] SVN: ZConfig/trunk/ fix race condition problem with emit when reopening logs
Fred Drake
fdrake at gmail.com
Sat Feb 11 06:04:52 UTC 2012
Log message for revision 124374:
fix race condition problem with emit when reopening logs
(https://bugs.launchpad.net/zconfig/+bug/481512; patch by Henning Eggers)
Changed:
U ZConfig/trunk/NEWS.txt
U ZConfig/trunk/ZConfig/components/logger/loghandler.py
U ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py
-=-
Modified: ZConfig/trunk/NEWS.txt
===================================================================
--- ZConfig/trunk/NEWS.txt 2012-02-11 05:40:21 UTC (rev 124373)
+++ ZConfig/trunk/NEWS.txt 2012-02-11 06:04:50 UTC (rev 124374)
@@ -6,7 +6,9 @@
ZConfig 2.9.1 (unreleased)
--------------------------
+- Make FileHandler.reopen thread safe.
+
ZConfig 2.9.0 (2011-03-22)
--------------------------
Modified: ZConfig/trunk/ZConfig/components/logger/loghandler.py
===================================================================
--- ZConfig/trunk/ZConfig/components/logger/loghandler.py 2012-02-11 05:40:21 UTC (rev 124373)
+++ ZConfig/trunk/ZConfig/components/logger/loghandler.py 2012-02-11 06:04:50 UTC (rev 124374)
@@ -84,8 +84,12 @@
_remove_from_reopenable(self._wr)
def reopen(self):
- self.stream.close()
- self.stream = open(self.baseFilename, self.mode)
+ self.acquire()
+ try:
+ self.stream.close()
+ self.stream = open(self.baseFilename, self.mode)
+ finally:
+ self.release()
class Win32FileHandler(FileHandler):
Modified: ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py
===================================================================
--- ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py 2012-02-11 05:40:21 UTC (rev 124373)
+++ ZConfig/trunk/ZConfig/components/logger/tests/test_logger.py 2012-02-11 06:04:50 UTC (rev 124374)
@@ -537,7 +537,24 @@
logger.removeHandler(handler)
handler.close()
+ def test_filehandler_reopen_thread_safety(self):
+ # The reopen method needs to do locking to avoid a race condition
+ # with emit calls. For simplicity we replace the "acquire" and
+ # "release" methods with dummies that record calls to them.
+ fn = self.mktemp()
+ h = self.handler_factory(fn)
+
+ calls = []
+ h.acquire = lambda: calls.append("acquire")
+ h.release = lambda: calls.append("release")
+
+ h.reopen()
+ h.close()
+
+ self.assertEqual(calls, ["acquire", "release"])
+
+
class TestReopeningRotatingLogfiles(TestReopeningLogfilesBase):
_sampleconfig_template = """
More information about the ZConfig
mailing list