This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author fdij
Recipients
Date 2005-09-05.21:12:16
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Consider the following code:

import logging
import logging.handlers

if __name__ == "__main__":
    fh = logging.handlers.RotatingFileHandler("log.txt")
    mh = logging.handlers.MemoryHandler(1024, 
logging.ERROR, fh)
    logging.getLogger().addHandler(mh)
    logging.getLogger().warning("next statement crashes")
    logging.shutdown()

which results in a crash due to operating on a closed 
file. The reason is that the shutdown flushes and closes 
all handlers in undefined order. In above case, first 
the 'fh' handlers is flushes and closed then the 'mh' 
handler.

The solution is to first flush all handlers times the 
number of handlers before closing them. Thus (omitting 
error handling):

def shutdown():
    for i in range(len(_handlers)):
        for h in _handlers.keys():
            h.flush()
    for h in _handlers.keys():
        h.close()
History
Date User Action Args
2007-08-23 14:34:15adminlinkissue1282539 messages
2007-08-23 14:34:15admincreate