[pypy-svn] r5025 - in pypy/trunk/src/pypy: interpreter module

arigo at codespeak.net arigo at codespeak.net
Thu Jun 10 14:46:16 CEST 2004


Author: arigo
Date: Thu Jun 10 14:46:15 2004
New Revision: 5025

Modified:
   pypy/trunk/src/pypy/interpreter/error.py
   pypy/trunk/src/pypy/interpreter/interactive.py
   pypy/trunk/src/pypy/module/sysmodule.py
Log:
implement half of sys.excepthook().  It can be called by Python code.
The missing half is actually calling it from the core.


Modified: pypy/trunk/src/pypy/interpreter/error.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/error.py	(original)
+++ pypy/trunk/src/pypy/interpreter/error.py	Thu Jun 10 14:46:15 2004
@@ -1,4 +1,3 @@
-from pypy.tool.tb_server import publish_exc
 import os, sys
 
 AUTO_DEBUG = os.getenv('PYPY_DEBUG')
@@ -150,14 +149,14 @@
             self.file.write('\n')
 
 # installing the excepthook for OperationErrors
-if hasattr(sys, 'excepthook'):   # not implemented on PyPy
-    def operr_excepthook(exctype, value, traceback):
-        if issubclass(exctype, OperationError):
-            value.debug_excs.append((exctype, value, traceback))
-            value.print_detailed_traceback()
-        else:
-            old_excepthook(exctype, value, traceback)
-            publish_exc((exctype, value, traceback))
-            
-    old_excepthook = sys.excepthook
-    sys.excepthook = operr_excepthook
+def operr_excepthook(exctype, value, traceback):
+    if issubclass(exctype, OperationError):
+        value.debug_excs.append((exctype, value, traceback))
+        value.print_detailed_traceback()
+    else:
+        old_excepthook(exctype, value, traceback)
+        from pypy.tool import tb_server
+        tb_server.publish_exc((exctype, value, traceback))
+
+old_excepthook = sys.excepthook
+sys.excepthook = operr_excepthook

Modified: pypy/trunk/src/pypy/interpreter/interactive.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/interactive.py	(original)
+++ pypy/trunk/src/pypy/interpreter/interactive.py	Thu Jun 10 14:46:15 2004
@@ -52,6 +52,9 @@
         except baseobjspace.OperationError, operationerr:
             # XXX insert exception info into the application-level sys.last_xxx
             operationerr.print_detailed_traceback(self.space)
+            # for debugging convenience we also insert the exception into
+            # the interpreter-level sys.last_xxx
+            sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info()
         else:
             try:
                 if sys.stdout.softspace:

Modified: pypy/trunk/src/pypy/module/sysmodule.py
==============================================================================
--- pypy/trunk/src/pypy/module/sysmodule.py	(original)
+++ pypy/trunk/src/pypy/module/sysmodule.py	Thu Jun 10 14:46:15 2004
@@ -19,3 +19,8 @@
 executable = ''
 prefix = ''
 version = '0.0.0 (not released yet)'
+
+# XXX not called by the core yet
+def excepthook(exctype, value, traceback):
+    from traceback import print_exception
+    print_exception(exctype, value, traceback)



More information about the Pypy-commit mailing list