Author vinay.sajip
Recipients socketpair, vinay.sajip
Date 2011-04-29.16:40:36
SpamBayes Score 9.99201e-16
Marked as misclassified No
Message-id <1304095239.1.0.00337454202502.issue11950@psf.upfronthosting.co.za>
In-reply-to
Content
It sounds to me as if there's a problem in yum that needs sorting out: I'm not sure why it would need dozens of loggers.

As your workaround snippet shows, leaking files is not due to loggers but due to handlers - they're a different animal. Handlers need not be leaked - they can just be closed when you're done with them. Handlers *are* stored in with weak references.

The design contract for loggers precludes using weak references for them. For example, if I use a library and from my logging initialization code get a reference to its top-level logger and e.g. set that logger's level, then when I've finished, there may not be any other references to that logger until I do an import of some library module. I wouldn't want the reference to the logger to go away, because then the library wouldn't know my intention regarding the level setting.

Normal practice would be to add a few handlers to yum's top-level logger and let descendant loggers inherit them. I'm not familiar with yum, so I don't know if/why it deviates from this common and best practice approach.

As you state, replacing {} with WeakValueDictionary() wouldn't solve the problem, and would the design assumptions/contract relating to loggers.

By the way the logging module does not store loggers in lists and dicts - just in a single dict in a manager. Handlers are stored in weak reference dicts as well as lists but that does not mean they are guaranteed to be garbage collected, since there could also be references to them in user code.

I don't know if you are just a yum user or a yum developer - in the latter case I'll be happy to work with you to look at yum's use of logging, and in the former case, feel free to post on yum mailing lists to the effect that I am willing to work with yum developers to improve the situation.

So I'll close this issue as invalid for the reasons given above, but I'm happy to work with yum developers to improve the situation you're experiencing. If in the course of doing that we find some way to improve the implementation of logging (in a backwards-compatible way, of course) then that's fine.
History
Date User Action Args
2011-04-29 16:41:36vinay.sajipunlinkissue11950 messages
2011-04-29 16:40:39vinay.sajipsetrecipients: + vinay.sajip, socketpair
2011-04-29 16:40:39vinay.sajipsetmessageid: <1304095239.1.0.00337454202502.issue11950@psf.upfronthosting.co.za>
2011-04-29 16:40:37vinay.sajiplinkissue11950 messages
2011-04-29 16:40:36vinay.sajipcreate