This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author oddthinking
Recipients oddthinking
Date 2010-11-04.03:49:53
SpamBayes Score 1.7845236e-10
Marked as misclassified No
Message-id <1288842596.1.0.996476383192.issue10306@psf.upfronthosting.co.za>
In-reply-to
Content
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.)
History
Date User Action Args
2010-11-04 03:49:56oddthinkingsetrecipients: + oddthinking
2010-11-04 03:49:56oddthinkingsetmessageid: <1288842596.1.0.996476383192.issue10306@psf.upfronthosting.co.za>
2010-11-04 03:49:54oddthinkinglinkissue10306 messages
2010-11-04 03:49:53oddthinkingcreate