diff options
author | Irit Katriel <iritkatriel@yahoo.com> | 2020-08-16 15:10:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-16 15:10:13 (GMT) |
commit | 2353d77fad7ed9d11d8a4d66b5dd1306cdb94125 (patch) | |
tree | b9237127698f84705a53825ff2f466b673d02237 /Lib/test | |
parent | fff3c28052e6b0750d6218e00acacd2fded4991a (diff) | |
download | cpython-2353d77fad7ed9d11d8a4d66b5dd1306cdb94125.zip cpython-2353d77fad7ed9d11d8a4d66b5dd1306cdb94125.tar.gz cpython-2353d77fad7ed9d11d8a4d66b5dd1306cdb94125.tar.bz2 |
bpo-41503: Fix race between setTarget and flush in logging.handlers.MemoryHandler (GH-21765)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_logging.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index eb5b926..d8b3727 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -1160,6 +1160,27 @@ class MemoryHandlerTest(BaseTest): # assert that no new lines have been added self.assert_log_lines(lines) # no change + def test_race_between_set_target_and_flush(self): + class MockRaceConditionHandler: + def __init__(self, mem_hdlr): + self.mem_hdlr = mem_hdlr + + def removeTarget(self): + self.mem_hdlr.setTarget(None) + + def handle(self, msg): + t = threading.Thread(target=self.removeTarget) + t.daemon = True + t.start() + + target = MockRaceConditionHandler(self.mem_hdlr) + self.mem_hdlr.setTarget(target) + + for _ in range(10): + time.sleep(0.005) + self.mem_logger.info("not flushed") + self.mem_logger.warning("flushed") + class ExceptionFormatter(logging.Formatter): """A special exception formatter.""" |