logging.shutdown() ValueError: I/O operation on closed file
j vickroy
robinjim at earthlink.net
Thu Nov 13 20:52:24 EST 2003
As a follow-up question, why is a handle object not removed from
logging._handlers when its (i.e., handle) close() procedure is applied?
That behavior appears to be responsible for the logging.shutdown() failure.
"j vickroy" <jim.vickroy at noaa.gov> wrote in message
news:bp0vaq$7lc$1 at boulder.noaa.gov...
> Hello,
>
> I'm trying to understand the behavior of the Python 2.3 logging module (MS
> Windows 2k) with regard to RotatingFileHandler. The following script
> illustrates a puzzling problem. What is wrong with this script?
>
> Thanks,
>
> -- jv
>
> BEGIN FILE _________________________________________
> '''
> This script terminates as follows:
>
> Traceback (most recent call last):
> File "D:\$PROJECTS\experimental\Py Logging\t_xb.py", line 63, in ?
> shutdown()
> File "C:\Python23\lib\logging\__init__.py", line 1195, in shutdown
> h.flush()
> File "C:\Python23\lib\logging\__init__.py", line 661, in flush
> self.stream.flush()
> ValueError: I/O operation on closed file
>
> What is wrong with it?
> '''
>
>
>
> from logging import getLogger, Formatter, shutdown, DEBUG, INFO,
WARNING,
> ERROR, CRITICAL
> from logging.handlers import RotatingFileHandler
>
>
>
> def logger_for(component):
> '''
> RETURNS a logger for the specified component.
>
> SIDE-EFFECTS
> (re)assigns the logger handler
> '''
>
> global handler
>
> logger = getLogger(component)
>
> if handler:
> handler.flush()
> handler.close()
> logger.removeHandler(handler)
>
> # In normal, operational mode, the following parameters:
> filename = '%s.log'%component
> mode = 'a'
> maxBytes = 100
> backupCount = 5
> # would be user-configurable "on the fly" hence the reason for this
> function.
>
> handler = RotatingFileHandler(filename, mode, maxBytes, backupCount)
>
> handler.setLevel(DEBUG)
>
> logger.addHandler(handler)
>
> return logger
>
>
>
> handler = None
>
> for i in range(20):
> log = logger_for('supplier')
> log.error('testing Python logging module')
>
> shutdown()
> END FILE _________________________________________
>
>
More information about the Python-list
mailing list