Kaydet (Commit) 1eb77a50 authored tarafından Vinay Sajip's avatar Vinay Sajip

Added lock acquisition/release around shared data structure manipulation

üst bd3490ab
......@@ -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()
#----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment