You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
logging FileHandler.close should acquire its lock before closing stream #55653
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:
assignee='https://github.com/vsajip'closed_at=<Date2011-03-08.23:00:36.614>created_at=<Date2011-03-08.19:54:33.229>labels= ['type-bug', 'library']
title='logging FileHandler.close should acquire its lock before closing stream'updated_at=<Date2011-03-11.18:49:08.616>user='https://bugs.python.org/AdamErnst'
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 closeself.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.
Activity
AdamErnst commentedon Mar 8, 2011
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.)
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.
python-dev commentedon 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/fc4d045e3170
New changeset c8b651b3a493 by Vinay Sajip in branch '2.7':
Issue bpo-11444: Merge fix from 2.6.
http://hg.python.org/cpython/rev/c8b651b3a493
New 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/16f8f359db9c
New changeset 39469645857a by Vinay Sajip in branch '3.2':
Issue bpo-11444: Merge fix from 3.1.
http://hg.python.org/cpython/rev/39469645857a
New changeset 1947cca7f583 by Vinay Sajip in branch 'default':
Issue bpo-11444: Merge fix from 3.2.
http://hg.python.org/cpython/rev/1947cca7f583
python-dev commentedon Mar 11, 2011
New 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