[llvm-branch-commits] [lldb] r198823 - Override the builtin quit() and exit() functions when using the embedded interactive interpreter so we don't close stdio and exit the process when the user types "quit()" or "sys.exit()" in the python interpreter.

Greg Clayton gclayton at apple.com
Wed Jan 8 17:06:26 PST 2014


Author: gclayton
Date: Wed Jan  8 19:06:25 2014
New Revision: 198823

URL: http://llvm.org/viewvc/llvm-project?rev=198823&view=rev
Log:
Override the builtin quit() and exit() functions when using the embedded interactive interpreter so we don't close stdio and exit the process when the user types "quit()" or "sys.exit()" in the python interpreter.


Modified:
    lldb/branches/iohandler/source/Interpreter/embedded_interpreter.py

Modified: lldb/branches/iohandler/source/Interpreter/embedded_interpreter.py
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/Interpreter/embedded_interpreter.py?rev=198823&r1=198822&r2=198823&view=diff
==============================================================================
--- lldb/branches/iohandler/source/Interpreter/embedded_interpreter.py (original)
+++ lldb/branches/iohandler/source/Interpreter/embedded_interpreter.py Wed Jan  8 19:06:25 2014
@@ -56,11 +56,16 @@ def run_python_interpreter (dict):
 g_run_one_line_str = None
 
 def run_python_interpreter (dict):
-   # Pass in the dictionary, for continuity from one session to the next.
-   code.interact(banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.", local=dict)
+    # Pass in the dictionary, for continuity from one session to the next.
+    setquit()
+    try:
+        code.interact(banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.", local=dict)
+    except SystemExit as e:
+        global g_builtin_override_called
+        if not g_builtin_override_called:
+            print 'Script exited with %s' %(e)
 
 def run_one_line (dict, input_string):
-    global g_builtin_override_called
     global g_run_one_line_str
     setquit()
     try:
@@ -71,5 +76,6 @@ def run_one_line (dict, input_string):
             repl.runsource (g_run_one_line_str)
 
     except SystemExit as e:
+        global g_builtin_override_called
         if not g_builtin_override_called:
             print 'Script exited with %s' %(e)





More information about the llvm-branch-commits mailing list