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

arigo at codespeak.net arigo at codespeak.net
Fri Jun 11 15:20:38 CEST 2004


Author: arigo
Date: Fri Jun 11 15:20:38 2004
New Revision: 5056

Modified:
   pypy/trunk/src/pypy/interpreter/interactive.py
   pypy/trunk/src/pypy/interpreter/py.py
   pypy/trunk/src/pypy/module/__builtin__module.py
   pypy/trunk/src/pypy/module/sysmodule.py
Log:
Nice ways to exit the PyPy interpreter: raise SystemExit, sys.exit(), Ctrl-D.


Modified: pypy/trunk/src/pypy/interpreter/interactive.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/interactive.py	(original)
+++ pypy/trunk/src/pypy/interpreter/interactive.py	Fri Jun 11 15:20:38 2004
@@ -50,8 +50,12 @@
         try:
             pycode.exec_code(self.space, self.w_globals, self.w_globals)
         except baseobjspace.OperationError, operationerr:
+            space = self.space
+            if operationerr.match(space, space.w_SystemExit):
+                # XXX fetch the exit code from somewhere inside the w_SystemExit
+                raise SystemExit
             # XXX insert exception info into the application-level sys.last_xxx
-            operationerr.print_detailed_traceback(self.space)
+            operationerr.print_detailed_traceback(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()

Modified: pypy/trunk/src/pypy/interpreter/py.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/py.py	(original)
+++ pypy/trunk/src/pypy/interpreter/py.py	Fri Jun 11 15:20:38 2004
@@ -62,7 +62,12 @@
                                     space.__class__.__name__)
             con.interact(banner)
     except:
-        sys.excepthook(*sys.exc_info())
+        exc_type, value, tb = sys.exc_info()
+        if (isinstance(exc_type, type(SystemExit)) and
+            issubclass(exc_type, SystemExit)):
+            pass   # don't print tracebacks for SystemExit
+        else:
+            sys.excepthook(exc_type, value, tb)
         tb_server.wait_until_interrupt()
             
     tb_server.stop()

Modified: pypy/trunk/src/pypy/module/__builtin__module.py
==============================================================================
--- pypy/trunk/src/pypy/module/__builtin__module.py	(original)
+++ pypy/trunk/src/pypy/module/__builtin__module.py	Fri Jun 11 15:20:38 2004
@@ -36,7 +36,10 @@
     if prompt is not None:
         sys.stdout.write(prompt)
         sys.stdout.flush()
-    return sys.stdin.readline()   # XXX review
+    line = sys.stdin.readline()
+    if not line:    # inputting an empty line gives line == '\n'
+        raise EOFError
+    return line
 
 def input():
     return eval(raw_input())

Modified: pypy/trunk/src/pypy/module/sysmodule.py
==============================================================================
--- pypy/trunk/src/pypy/module/sysmodule.py	(original)
+++ pypy/trunk/src/pypy/module/sysmodule.py	Fri Jun 11 15:20:38 2004
@@ -25,3 +25,6 @@
 def excepthook(exctype, value, traceback):
     from traceback import print_exception
     print_exception(exctype, value, traceback)
+
+def exit(exitcode=0):
+    raise SystemExit(exitcode)



More information about the Pypy-commit mailing list