diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2006-02-09 08:31:00 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2006-02-09 08:31:00 (GMT) |
commit | 1eb77a50c86bd77eac0bc913d8b59e1dc3bb7687 (patch) | |
tree | 04e7e6692ee7ca06c2ee3b505bb1355621021234 | |
parent | bd3490abdb94aca32c6f42b450444554b28d4bf1 (diff) | |
download | cpython-1eb77a50c86bd77eac0bc913d8b59e1dc3bb7687.zip cpython-1eb77a50c86bd77eac0bc913d8b59e1dc3bb7687.tar.gz cpython-1eb77a50c86bd77eac0bc913d8b59e1dc3bb7687.tar.bz2 |
Added lock acquisition/release around shared data structure manipulation
-rw-r--r-- | Lib/test/test_logging.py | 53 |
1 files 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() #---------------------------------------------------------------------------- |