Wording suggestion for documentation (Data Model)

Jason R. Coombs jaraco at jaraco.com
Fri Jun 13 02:16:52 CEST 2008


#!python

"""
In the documentation for __del__ (under Python Language Reference/Data
Model), the following warning is indicated:

Warning [Caveat in 2.6]: Due to the precarious circumstances under
which __del__() methods are invoked, exceptions that occur during
their execution are ignored, and a warning is printed to sys.stderr
instead. ...

That statement appears, however, to be incorrect.

Perhaps the warning should be re-worded to say "When __del__() methods
are invoked, exceptions that occur during the execution of such
methods must be caught and handled within the scope of the __del__()
method call.  Otherwise unhandled exceptions will be ignored except
for a warning printed to sys.stderr instead."

For example,
"""

class X(object):
	def __del__(self):
		print 'deleting', self
		try:
			raise Exception, "OMG!"
		except:
			print 'caught exception, np'
		print 'made it past the exception'

x = X()
del x

print 'x has been deleted, now what?'

"""
All this prints something like:

deleting <__main__.X object at 0x01BB1A50>
caught exception, np
made it past the exception
x has been deleted, now what?
"""

# - Jason R. Coombs



More information about the Python-list mailing list