Repository navigation
logging FileHandler.close should acquire its lock before closing stream #55653
Description
Activity
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.
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 8, 2011 New changeset fc4d045e3170 by Vinay Sajip in branch '2.6':
Issue bpo-11444: Lock handlers while flushing/closing during shutdown.
http://hg.python.org/cpython/rev/fc4d045e3170New changeset c8b651b3a493 by Vinay Sajip in branch '2.7':
Issue bpo-11444: Merge fix from 2.6.
http://hg.python.org/cpython/rev/c8b651b3a493New changeset 16f8f359db9c by Vinay Sajip in branch '3.1':
Issue bpo-11444: Lock handlers while flushing/closing during shutdown.
http://hg.python.org/cpython/rev/16f8f359db9cNew changeset 39469645857a by Vinay Sajip in branch '3.2':
Issue bpo-11444: Merge fix from 3.1.
http://hg.python.org/cpython/rev/39469645857aNew changeset 1947cca7f583 by Vinay Sajip in branch 'default':
Issue bpo-11444: Merge fix from 3.2.
http://hg.python.org/cpython/rev/1947cca7f583New changeset d6626c9fc28d by Vinay Sajip in branch '2.6':
Reverted bug fixes for bpo-11444 (fc4d045e3170) and bpo-11424 (b9d76846bb1c), which should not have been made in this branch.
http://hg.python.org/cpython/rev/d6626c9fc28d
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: