[Python-checkins] r53234 - peps/trunk/pep-0344.txt
ka-ping.yee
python-checkins at python.org
Thu Jan 4 03:53:06 CET 2007
Author: ka-ping.yee
Date: Thu Jan 4 03:53:05 2007
New Revision: 53234
Modified:
peps/trunk/pep-0344.txt
Log:
Add a discussion of the cyclic garbage issue.
Modified: peps/trunk/pep-0344.txt
==============================================================================
--- peps/trunk/pep-0344.txt (original)
+++ peps/trunk/pep-0344.txt Thu Jan 4 03:53:05 2007
@@ -339,7 +339,7 @@
library contains no mention of such attributes.
-Open Issues
+Open Issue: Extra Information
Walter Dörwald [11] expressed a desire to attach extra information
to an exception during its upward propagation without changing its
@@ -348,10 +348,16 @@
establishing conventions for other informational attributes on
exceptions.
+
+Open Issue: Suppressing Context
+
As written, this PEP makes it impossible to suppress '__context__',
since setting exc.__context__ to None in an 'except' or 'finally'
clause will only result in it being set again when exc is raised.
+
+Open Issue: Limiting Exception Types
+
To improve encapsulation, library implementors may want to wrap all
implementation-level exceptions with an application-level exception.
One could try to wrap exceptions by writing this:
@@ -378,6 +384,9 @@
except *, exc:
raise ApplicationError from exc
+
+Open Issue: yield
+
The exception context is lost when a 'yield' statement is executed;
resuming the frame after the 'yield' does not restore the context.
Addressing this problem is out of the scope of this PEP; it is not a
@@ -398,6 +407,36 @@
(deprecated), not NoneType
+Open Issue: Garbage Collection
+
+ The strongest objection to this proposal has been that it creates
+ cycles between exceptions and stack frames [12]. Collection of
+ cyclic garbage (and therefore resource release) can be greatly
+ delayed.
+
+ >>> try:
+ >>> 1/0
+ >>> except Exception, err:
+ >>> pass
+
+ will introduce a cycle from err -> traceback -> stack frame -> err,
+ keeping all locals in the same scope alive until the next GC happens.
+
+ Today, these locals would go out of scope. There is lots of code
+ which assumes that "local" resources -- particularly open files -- will
+ be closed quickly. If closure has to wait for the next GC, a program
+ (which runs fine today) may run out of file handles.
+
+ Making the __traceback__ attribute a weak reference would avoid the
+ problems with cyclic garbage. Unfortunately, it would make saving
+ the Exception for later (as unittest does) more awkward, and it would
+ not allow as much cleanup of the sys module.
+
+ A possible alternate solution, suggested by Adam Olsen, would be to
+ instead turn the reference from the stack frame to the 'err' variable
+ into a weak reference when the variable goes out of scope [13].
+
+
Possible Future Compatible Changes
These changes are consistent with the appearance of exceptions as
@@ -478,6 +517,12 @@
[11] Walter Dörwald suggests wrapping exceptions to add details
http://mail.python.org/pipermail/python-dev/2003-June/036148.html
+ [12] Guido van Rossum restates the objection to cyclic trash
+ http://mail.python.org/pipermail/python-3000/2007-January/005322.html
+
+ [13] Adam Olsen suggests using a weakref from stack frame to exception
+ http://mail.python.org/pipermail/python-3000/2007-January/005363.html
+
Copyright
More information about the Python-checkins
mailing list