New submission from Julian <python_...@somethinkodd.com>: If a weakref callback raises an exception, weakref writes out some text (to stderr, I think) and ignores it.
I think it would be more appropriate if weakref emitted that text using the Python warning module, to allow it to be better controlled. Consider this code with two foolish mistakes in it: --------- import warnings import weakref warnings.simplefilter('ignore') # Whoops, ignoring warnings is foolish. def callback(condemned_object): raise Exception("Failure") # Whoops, raising an exception in a callback is foolish. class RandomObject(object): pass strong_ref = RandomObject() wr = weakref.proxy(strong_ref, callback) print "Removing the only strong reference" strong_ref = None # No guarantee that the garbage collector will trigger # in practice, in CPython, it does. print "Shutting down now." --------- When I run this I get: Removing the only strong reference Exception Exception: Exception('Failure',) in <function callback at 0x0280A1B0> ignored Shutting down now. The exception text is output even though I don't want it to be. To help me debug, I want for the exception text to be manageable (not by ignoring it, like in the example above, but using the other warnings module features.) ---------- components: Library (Lib) messages: 120375 nosy: oddthinking priority: normal severity: normal status: open title: Weakref callback exceptions should be turned into warnings. type: behavior versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue10306> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com