[Python-checkins] bpo-41739: Fix test_logging.test_race_between_set_target_and_flush() (GH-22655) (GH-22656) (GH-22662)
Miss Skeleton (bot)
webhook-mailer at python.org
Mon Oct 12 04:51:41 EDT 2020
https://github.com/python/cpython/commit/33057c70920787627f2c94d08eb5d33c31f8bdd9
commit: 33057c70920787627f2c94d08eb5d33c31f8bdd9
branch: 3.8
author: Miss Skeleton (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020年10月12日T10:51:10+02:00
summary:
bpo-41739: Fix test_logging.test_race_between_set_target_and_flush() (GH-22655) (GH-22656) (GH-22662)
The test now waits until all threads complete to avoid leaking
running threads.
Also, use regular threads rather than daemon threads.
(cherry picked from commit 13ff396c019d548ba181cf22c6f39309a300723c)
(cherry picked from commit f5393dc2a0ced7bf670ebc56b5fd10a3eb328d1a)
Co-authored-by: Victor Stinner <vstinner at python.org>
Co-authored-by: Victor Stinner <vstinner at python.org>
files:
A Misc/NEWS.d/next/Tests/2020-10-12-00-11-47.bpo-41739.wSCc4K.rst
M Lib/test/test_logging.py
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index cea51b455eed2..b9392aefd4476 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -1177,22 +1177,27 @@ def test_race_between_set_target_and_flush(self):
class MockRaceConditionHandler:
def __init__(self, mem_hdlr):
self.mem_hdlr = mem_hdlr
+ self.threads = []
def removeTarget(self):
self.mem_hdlr.setTarget(None)
def handle(self, msg):
- t = threading.Thread(target=self.removeTarget)
- t.daemon = True
- t.start()
+ thread = threading.Thread(target=self.removeTarget)
+ self.threads.append(thread)
+ thread.start()
target = MockRaceConditionHandler(self.mem_hdlr)
- self.mem_hdlr.setTarget(target)
+ try:
+ self.mem_hdlr.setTarget(target)
- for _ in range(10):
- time.sleep(0.005)
- self.mem_logger.info("not flushed")
- self.mem_logger.warning("flushed")
+ for _ in range(10):
+ time.sleep(0.005)
+ self.mem_logger.info("not flushed")
+ self.mem_logger.warning("flushed")
+ finally:
+ for thread in target.threads:
+ support.join_thread(thread)
class ExceptionFormatter(logging.Formatter):
diff --git a/Misc/NEWS.d/next/Tests/2020-10-12-00-11-47.bpo-41739.wSCc4K.rst b/Misc/NEWS.d/next/Tests/2020-10-12-00-11-47.bpo-41739.wSCc4K.rst
new file mode 100644
index 0000000000000..7aee2b9444472
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2020-10-12-00-11-47.bpo-41739.wSCc4K.rst
@@ -0,0 +1,2 @@
+Fix test_logging.test_race_between_set_target_and_flush(): the test now
+waits until all threads complete to avoid leaking running threads.
More information about the Python-checkins
mailing list