Vinay Sajip <vinay_sa...@yahoo.co.uk> added the comment:

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.

----------
assignee:  -> vinay.sajip
nosy: +vinay.sajip
resolution:  -> invalid
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11950>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to