From 1eb77a50c86bd77eac0bc913d8b59e1dc3bb7687 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 9 Feb 2006 08:31:00 +0000 Subject: Added lock acquisition/release around shared data structure manipulation --- Lib/test/test_logging.py | 53 +++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index f398720..bf1e234 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -466,9 +466,13 @@ def test4(): conf = globals()['config%d' % i] sys.stdout.write('config%d: ' % i) loggerDict = logging.getLogger().manager.loggerDict - saved_handlers = logging._handlers.copy() - saved_handler_list = logging._handlerList[:] - saved_loggers = loggerDict.copy() + logging._acquireLock() + try: + saved_handlers = logging._handlers.copy() + saved_handler_list = logging._handlerList[:] + saved_loggers = loggerDict.copy() + finally: + logging._releaseLock() try: fn = tempfile.mktemp(".ini") f = open(fn, "w") @@ -483,12 +487,16 @@ def test4(): message('ok.') os.remove(fn) finally: - logging._handlers.clear() - logging._handlers.update(saved_handlers) - logging._handlerList = saved_handler_list - loggerDict = logging.getLogger().manager.loggerDict - loggerDict.clear() - loggerDict.update(saved_loggers) + logging._acquireLock() + try: + logging._handlers.clear() + logging._handlers.update(saved_handlers) + logging._handlerList = saved_handler_list + loggerDict = logging.getLogger().manager.loggerDict + loggerDict.clear() + loggerDict.update(saved_loggers) + finally: + logging._releaseLock() #---------------------------------------------------------------------------- # Test 5 @@ -527,9 +535,13 @@ class FriendlyFormatter (logging.Formatter): def test5(): loggerDict = logging.getLogger().manager.loggerDict - saved_handlers = logging._handlers.copy() - saved_handler_list = logging._handlerList[:] - saved_loggers = loggerDict.copy() + logging._acquireLock() + try: + saved_handlers = logging._handlers.copy() + saved_handler_list = logging._handlerList[:] + saved_loggers = loggerDict.copy() + finally: + logging._releaseLock() try: fn = tempfile.mktemp(".ini") f = open(fn, "w") @@ -542,13 +554,16 @@ def test5(): logging.exception("just testing") os.remove(fn) finally: - logging._handlers.clear() - logging._handlers.update(saved_handlers) - logging._handlerList = saved_handler_list - loggerDict = logging.getLogger().manager.loggerDict - loggerDict.clear() - loggerDict.update(saved_loggers) - + logging._acquireLock() + try: + logging._handlers.clear() + logging._handlers.update(saved_handlers) + logging._handlerList = saved_handler_list + loggerDict = logging.getLogger().manager.loggerDict + loggerDict.clear() + loggerDict.update(saved_loggers) + finally: + logging._releaseLock() #---------------------------------------------------------------------------- -- cgit v0.12