mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Added a config-main General option to delete sys.exitfunc. The default
is not to do that. VPython and student environment support. M PyShell.py M config-main.def M run.py
This commit is contained in:
parent
f7c822073e
commit
62df044885
3 changed files with 24 additions and 8 deletions
|
@ -312,13 +312,14 @@ class ModifiedInterpreter(InteractiveInterpreter):
|
||||||
InteractiveInterpreter.__init__(self, locals=locals)
|
InteractiveInterpreter.__init__(self, locals=locals)
|
||||||
self.save_warnings_filters = None
|
self.save_warnings_filters = None
|
||||||
self.restarting = False
|
self.restarting = False
|
||||||
|
self.subprocess_arglist = self.build_subprocess_arglist()
|
||||||
|
|
||||||
port = 8833
|
port = 8833
|
||||||
rpcclt = None
|
rpcclt = None
|
||||||
rpcpid = None
|
rpcpid = None
|
||||||
|
|
||||||
def spawn_subprocess(self):
|
def spawn_subprocess(self):
|
||||||
args = self.build_subprocess_arglist()
|
args = self.subprocess_arglist
|
||||||
self.rpcpid = os.spawnv(os.P_NOWAIT, args[0], args)
|
self.rpcpid = os.spawnv(os.P_NOWAIT, args[0], args)
|
||||||
|
|
||||||
def build_subprocess_arglist(self):
|
def build_subprocess_arglist(self):
|
||||||
|
@ -326,10 +327,12 @@ class ModifiedInterpreter(InteractiveInterpreter):
|
||||||
# Maybe IDLE is installed and is being accessed via sys.path,
|
# Maybe IDLE is installed and is being accessed via sys.path,
|
||||||
# or maybe it's not installed and the idle.py script is being
|
# or maybe it's not installed and the idle.py script is being
|
||||||
# run from the IDLE source directory.
|
# run from the IDLE source directory.
|
||||||
|
del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc',
|
||||||
|
default=False, type='bool')
|
||||||
if __name__ == 'idlelib.PyShell':
|
if __name__ == 'idlelib.PyShell':
|
||||||
command = "__import__('idlelib.run').run.main()"
|
command = "__import__('idlelib.run').run.main(" + `del_exitf` +")"
|
||||||
else:
|
else:
|
||||||
command = "__import__('run').main()"
|
command = "__import__('run').main(" + `del_exitf` + ")"
|
||||||
return [sys.executable] + w + ["-c", command, str(self.port)]
|
return [sys.executable] + w + ["-c", command, str(self.port)]
|
||||||
|
|
||||||
def start_subprocess(self):
|
def start_subprocess(self):
|
||||||
|
|
|
@ -43,6 +43,7 @@ editor-on-startup= 0
|
||||||
autosave= 0
|
autosave= 0
|
||||||
print-command-posix=lpr %s
|
print-command-posix=lpr %s
|
||||||
print-command-win=start /min notepad /p %s
|
print-command-win=start /min notepad /p %s
|
||||||
|
delete-exitfunc= 0
|
||||||
|
|
||||||
[EditorWindow]
|
[EditorWindow]
|
||||||
width= 80
|
width= 80
|
||||||
|
|
|
@ -24,7 +24,7 @@ import __main__
|
||||||
exit_now = False
|
exit_now = False
|
||||||
quitting = False
|
quitting = False
|
||||||
|
|
||||||
def main():
|
def main(del_exitfunc=False):
|
||||||
"""Start the Python execution server in a subprocess
|
"""Start the Python execution server in a subprocess
|
||||||
|
|
||||||
In the Python subprocess, RPCServer is instantiated with handlerclass
|
In the Python subprocess, RPCServer is instantiated with handlerclass
|
||||||
|
@ -44,6 +44,8 @@ def main():
|
||||||
"""
|
"""
|
||||||
global exit_now
|
global exit_now
|
||||||
global quitting
|
global quitting
|
||||||
|
global no_exitfunc
|
||||||
|
no_exitfunc = del_exitfunc
|
||||||
port = 8833
|
port = 8833
|
||||||
if sys.argv[1:]:
|
if sys.argv[1:]:
|
||||||
port = int(sys.argv[1])
|
port = int(sys.argv[1])
|
||||||
|
@ -57,7 +59,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
if exit_now:
|
if exit_now:
|
||||||
try:
|
try:
|
||||||
sys.exit(0)
|
exit()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
# exiting but got an extra KBI? Try again!
|
# exiting but got an extra KBI? Try again!
|
||||||
continue
|
continue
|
||||||
|
@ -83,7 +85,7 @@ def main():
|
||||||
except:
|
except:
|
||||||
# Link didn't work, print same exception to __stderr__
|
# Link didn't work, print same exception to __stderr__
|
||||||
traceback.print_exception(type, value, tb, file=sys.__stderr__)
|
traceback.print_exception(type, value, tb, file=sys.__stderr__)
|
||||||
sys.exit(0)
|
exit()
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -159,6 +161,16 @@ def flush_stdout():
|
||||||
except (AttributeError, EOFError):
|
except (AttributeError, EOFError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def exit():
|
||||||
|
"""Exit subprocess, possibly after first deleting sys.exitfunc
|
||||||
|
|
||||||
|
If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
|
||||||
|
sys.exitfunc will be removed before exiting. (VPython support)
|
||||||
|
|
||||||
|
"""
|
||||||
|
if no_exitfunc:
|
||||||
|
del sys.exitfunc
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
class MyRPCServer(rpc.RPCServer):
|
class MyRPCServer(rpc.RPCServer):
|
||||||
|
|
||||||
|
@ -186,7 +198,7 @@ class MyRPCServer(rpc.RPCServer):
|
||||||
traceback.print_exc(file=erf)
|
traceback.print_exc(file=erf)
|
||||||
print>>erf, '\n*** Unrecoverable, server exiting!'
|
print>>erf, '\n*** Unrecoverable, server exiting!'
|
||||||
print>>erf, '-'*40
|
print>>erf, '-'*40
|
||||||
sys.exit(0)
|
exit()
|
||||||
|
|
||||||
|
|
||||||
class MyHandler(rpc.RPCHandler):
|
class MyHandler(rpc.RPCHandler):
|
||||||
|
@ -229,7 +241,7 @@ class Executive:
|
||||||
exec code in self.locals
|
exec code in self.locals
|
||||||
except:
|
except:
|
||||||
if quitting:
|
if quitting:
|
||||||
sys.exit(0)
|
exit()
|
||||||
# even print a user code SystemExit exception, continue
|
# even print a user code SystemExit exception, continue
|
||||||
print_exception()
|
print_exception()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue