From: <zy...@us...> - 2008-10-19 23:18:28
|
Revision: 5472 http://jython.svn.sourceforge.net/jython/?rev=5472&view=rev Author: zyasoft Date: 2008-10-19 23:18:22 +0000 (Sun, 19 Oct 2008) Log Message: ----------- PEP 342 specifies that an exception raised by close during finalization should be output to stderr, so we now do that. Fixed a minor doctest output formatting issue so that the desired syntax error is properly seen. Modified Paths: -------------- trunk/jython/Lib/test/test_generators.py trunk/jython/src/org/python/core/PyGenerator.java Modified: trunk/jython/Lib/test/test_generators.py =================================================================== --- trunk/jython/Lib/test/test_generators.py 2008-10-19 23:17:44 UTC (rev 5471) +++ trunk/jython/Lib/test/test_generators.py 2008-10-19 23:18:22 UTC (rev 5472) @@ -867,7 +867,7 @@ <type 'generator'> ->>> def f(): +>>> def f(): #doctest: +IGNORE_EXCEPTION_DETAIL, +NORMALIZE_WHITESPACE ... if 0: ... lambda x: x # shouldn't trigger here ... return # or here @@ -1646,8 +1646,6 @@ >>> g.close() # close normally And finalization. But we have to force the timing of GC here, since we are running on Jython: ->>> import gc ->>> from time import sleep >>> def f(): ... try: yield ... finally: @@ -1655,7 +1653,7 @@ >>> g = f() >>> g.next() ->>> del g; gc.collect(); sleep(1); gc.collect() +>>> del g; extra_collect() exiting @@ -1680,7 +1678,7 @@ >>> old, sys.stderr = sys.stderr, StringIO.StringIO() >>> g = f() >>> g.next() ->>> del g; gc.collect(); sleep(1); gc.collect() +>>> del g; extra_collect() >>> sys.stderr.getvalue().startswith( ... "Exception RuntimeError" ... ) @@ -1789,7 +1787,6 @@ >>> import sys, StringIO >>> from time import sleep ->>> import gc >>> old = sys.stderr >>> try: ... sys.stderr = StringIO.StringIO() @@ -1798,7 +1795,7 @@ ... raise RuntimeError ... ... l = Leaker() -... del l; gc.collect(); sleep(1); gc.collect() +... del l; extra_collect() ... err = sys.stderr.getvalue().strip() ... err.startswith( ... "Exception RuntimeError in <" @@ -1837,6 +1834,13 @@ from test import test_support, test_generators test_support.run_doctest(test_generators, verbose) +def extra_collect(): + import gc + from time import sleep + + gc.collect(); sleep(1); gc.collect(); sleep(0.1); gc.collect() + + # This part isn't needed for regrtest, but for running the test directly. if __name__ == "__main__": test_main(1) Modified: trunk/jython/src/org/python/core/PyGenerator.java =================================================================== --- trunk/jython/src/org/python/core/PyGenerator.java 2008-10-19 23:17:44 UTC (rev 5471) +++ trunk/jython/src/org/python/core/PyGenerator.java 2008-10-19 23:18:22 UTC (rev 5472) @@ -82,7 +82,23 @@ return; try { close(); + } catch (PyException e) { + // PEP 342 specifies that if an exception is raised by close, + // we output to stderr and then forget about it; + String className = PyException.exceptionClassName(e.type); + int lastDot = className.lastIndexOf('.'); + if (lastDot != -1) { + className = className.substring(lastDot + 1); + } + PyString m = Py.newString( + String.format("Exception %s: %s in %s", + className, + e.value.__repr__().toString(), + this.__repr__().toString())); + Py.println(Py.getSystemState().stderr, m); } catch (Throwable e) { + // but we currently ignore any Java exception completely. perhaps we + // can also output something meaningful too? } finally { super.finalize(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |