Be careful with logging locks and unopened streams

Slight modification of patch suggested by sirkonst.
This commit is contained in:
Randall Leeds 2012-03-27 17:14:29 -07:00
parent ac223ae639
commit 1757567d2f

View File

@ -206,9 +206,12 @@ class Logger(object):
for handler in log.handlers: for handler in log.handlers:
if isinstance(handler, logging.FileHandler): if isinstance(handler, logging.FileHandler):
handler.acquire() handler.acquire()
try:
if handler.stream:
handler.stream.close() handler.stream.close()
handler.stream = open(handler.baseFilename, handler.stream = open(handler.baseFilename,
handler.mode) handler.mode)
finally:
handler.release() handler.release()
def close_on_exec(self): def close_on_exec(self):
@ -216,7 +219,10 @@ class Logger(object):
for handler in log.handlers: for handler in log.handlers:
if isinstance(handler, logging.FileHandler): if isinstance(handler, logging.FileHandler):
handler.acquire() handler.acquire()
try:
if handler.stream:
util.close_on_exec(handler.stream.fileno()) util.close_on_exec(handler.stream.fileno())
finally:
handler.release() handler.release()