Author vinay.sajip
Recipients OG7, amaury.forgeotdarc, jnoller, pitrou, vinay.sajip
Date 2009-11-24.18:01:40
SpamBayes Score 2.30205e-12
Marked as misclassified No
Message-id <182498.32330.qm@web25806.mail.ukl.yahoo.com>
In-reply-to <1259075834.3450.11.camel@localhost>
Content
> In general it would be nice if logging were more conservative (or

> cautious) when it comes to keeping objects persistent. It is too easy to
> fall into a trap and experience memory leaks.

I've checked in a change into trunk today which might improve matters. Handler.__init__ no longer adds the handler instance to the _handlers map unconditionally, but still adds it to the _handlerList array. The only place this array is actually used is in the shutdown() API, which is registered to be run via atexit. It flushes and closes  all the handlers in the list, so that any data in logging buffers gets flushed before the process exits.

The _handlers dict is now used to hold a mapping between handler names and handlers - the name property was added to Handler in the change I checked in today. This will be used by the dictConfig functionality which is proposed in PEP 391. If no name property is set on a Handler, then this will not add any additional references to handlers.

Python 2.7a0 (trunk:75403, Oct 14 2009, 20:14:09) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
[49139 refs]
>>> logging._handlerList
[]
[49146 refs]
>>> logging.Handler()
<logging.Handler object at 0x00B72658>
[49179 refs]
>>> logging.Handler()
<logging.Handler object at 0x00B72620>
[49202 refs]
>>> logging.Handler()
<logging.Handler object at 0x00B764D0>
[49225 refs]
>>> logging._handlerList
[<logging.Handler object at 0x00B764D0>, <logging.Handler object at 0x00B72620>,
 <logging.Handler object at 0x00B72658>]
[49225 refs]
>>> logging.shutdown()
[49156 refs]
>>> logging._handlerList
[]
[49156 refs]
>>>
History
Date User Action Args
2009-11-24 18:01:43vinay.sajipsetrecipients: + vinay.sajip, amaury.forgeotdarc, pitrou, OG7, jnoller
2009-11-24 18:01:41vinay.sajiplinkissue6615 messages
2009-11-24 18:01:40vinay.sajipcreate