[New-bugs-announce] [issue11444] logging FileHandler.close should acquire its lock before closing stream

Adam Ernst report at bugs.python.org
Tue Mar 8 20:54:34 CET 2011


New submission from Adam Ernst <adamjernst at gmail.com>:

This is my first report, apologies if I missed any tracker etiquette.

The logging module registers shutdown() to run via atexit. shutdown() calls flush() and close() on each handler.

However if a FileHandler is writing to a file while shutdown() is executing, an IOError will be raised as the file is being closed while written to. (This can happen if you use daemon threads, which can still be running while exiting.)


Traceback (most recent call last):
  File "/usr/local/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/local/lib/python2.7/logging/__init__.py", line 1616, in shutdown
    h.close()
  File "/usr/local/lib/python2.7/logging/__init__.py", line 898, in close
    self.stream.close()
IOError: close() called during concurrent operation on the same file object.


I'm not familiar with the internals of logging, but it seems that FileHandler should call self.acquire()/self.release() around its close and flush operations. Otherwise a daemon thread might be emitting a record while closing the handler.

----------
components: Library (Lib)
messages: 130362
nosy: Adam.Ernst
priority: normal
severity: normal
status: open
title: logging FileHandler.close should acquire its lock before closing stream
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11444>
_______________________________________


More information about the New-bugs-announce mailing list