Message233531
Data point: if you print out _handlerList immediately after the dictConfig() call, it *is* there, as I would have expected. The following script saved as logtest6.py:
from datetime import datetime
from time import sleep
import sys
if __name__ == '__main__':
LOGGING = {
'version': 1,
'handlers': {
'logfile': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/tmp/debug.log',
},
},
}
print('%s: starting' % (datetime.now(),))
from logging.config import dictConfig
dictConfig(LOGGING)
from logging import _handlerList
print('%s: after dictconfig' % (datetime.now(),))
sys.stdout.flush()
print('_handlerList 1:', _handlerList)
# using importlib on a new file triggers the warnings
import importlib, shutil, os
print('_handlerList 2:', _handlerList)
shutil.copy(__file__, __file__ + '.new')
os.unlink(__file__)
os.rename(__file__ + '.new', __file__)
importlib.import_module('logtest6')
sys.stderr.flush()
print('%s: after error' % (datetime.now(),))
sys.stdout.flush()
sleep(5)
print('%s: after sleep' % (datetime.now(),))
# Vinay Sajip wrote:
# > The handlers are AFAIK referenced - if you peek at
# logging._handlerList or logging._handlers you should see them in
# there.
from logging import _handlerList, _handlers
print('_handlerList 3:', _handlerList)
else:
print('imported once')
When run, yields
$ python3.4 logtest6.py
2015-01-06 12:26:46.910634: starting
2015-01-06 12:26:47.290223: after dictconfig
_handlerList 1: [<weakref at 0xb7223e34; to 'FileHandler' at 0xb71680dc>]
/home/vinay/projects/python/3.4/Lib/collections/__init__.py:373: ResourceWarning: unclosed file <_io.FileIO name='/tmp/debug.log' mode='ab'>
exec(class_definition, namespace)
_handlerList 2: []
imported once
2015-01-06 12:26:47.388877: after error
2015-01-06 12:26:52.394514: after sleep
_handlerList 3: [] |
|
Date |
User |
Action |
Args |
2015-01-06 12:29:41 | vinay.sajip | set | recipients:
+ vinay.sajip, wdoekes |
2015-01-06 12:29:41 | vinay.sajip | set | messageid: <1420547381.63.0.218120180719.issue23010@psf.upfronthosting.co.za> |
2015-01-06 12:29:41 | vinay.sajip | link | issue23010 messages |
2015-01-06 12:29:41 | vinay.sajip | create | |
|