Skip to content

Commit 62df044

Browse files
committed
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
1 parent f7c8220 commit 62df044

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

Lib/idlelib/PyShell.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,24 +312,27 @@ def __init__(self, tkconsole):
312312
InteractiveInterpreter.__init__(self, locals=locals)
313313
self.save_warnings_filters = None
314314
self.restarting = False
315+
self.subprocess_arglist = self.build_subprocess_arglist()
315316

316317
port = 8833
317318
rpcclt = None
318319
rpcpid = None
319320

320321
def spawn_subprocess(self):
321-
args = self.build_subprocess_arglist()
322+
args = self.subprocess_arglist
322323
self.rpcpid = os.spawnv(os.P_NOWAIT, args[0], args)
323324

324325
def build_subprocess_arglist(self):
325326
w = ['-W' + s for s in sys.warnoptions]
326327
# Maybe IDLE is installed and is being accessed via sys.path,
327328
# or maybe it's not installed and the idle.py script is being
328329
# run from the IDLE source directory.
330+
del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc',
331+
default=False, type='bool')
329332
if __name__ == 'idlelib.PyShell':
330-
command = "__import__('idlelib.run').run.main()"
333+
command = "__import__('idlelib.run').run.main(" + `del_exitf` +")"
331334
else:
332-
command = "__import__('run').main()"
335+
command = "__import__('run').main(" + `del_exitf` + ")"
333336
return [sys.executable] + w + ["-c", command, str(self.port)]
334337

335338
def start_subprocess(self):

Lib/idlelib/config-main.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ editor-on-startup= 0
4343
autosave= 0
4444
print-command-posix=lpr %s
4545
print-command-win=start /min notepad /p %s
46+
delete-exitfunc= 0
4647

4748
[EditorWindow]
4849
width= 80

Lib/idlelib/run.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
exit_now = False
2525
quitting = False
2626

27-
def main():
27+
def main(del_exitfunc=False):
2828
"""Start the Python execution server in a subprocess
2929
3030
In the Python subprocess, RPCServer is instantiated with handlerclass
@@ -44,6 +44,8 @@ def main():
4444
"""
4545
global exit_now
4646
global quitting
47+
global no_exitfunc
48+
no_exitfunc = del_exitfunc
4749
port = 8833
4850
if sys.argv[1:]:
4951
port = int(sys.argv[1])
@@ -57,7 +59,7 @@ def main():
5759
try:
5860
if exit_now:
5961
try:
60-
sys.exit(0)
62+
exit()
6163
except KeyboardInterrupt:
6264
# exiting but got an extra KBI? Try again!
6365
continue
@@ -83,7 +85,7 @@ def main():
8385
except:
8486
# Link didn't work, print same exception to __stderr__
8587
traceback.print_exception(type, value, tb, file=sys.__stderr__)
86-
sys.exit(0)
88+
exit()
8789
else:
8890
continue
8991

@@ -159,6 +161,16 @@ def flush_stdout():
159161
except (AttributeError, EOFError):
160162
pass
161163

164+
def exit():
165+
"""Exit subprocess, possibly after first deleting sys.exitfunc
166+
167+
If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
168+
sys.exitfunc will be removed before exiting. (VPython support)
169+
170+
"""
171+
if no_exitfunc:
172+
del sys.exitfunc
173+
sys.exit(0)
162174

163175
class MyRPCServer(rpc.RPCServer):
164176

@@ -186,7 +198,7 @@ def handle_error(self, request, client_address):
186198
traceback.print_exc(file=erf)
187199
print>>erf, '\n*** Unrecoverable, server exiting!'
188200
print>>erf, '-'*40
189-
sys.exit(0)
201+
exit()
190202

191203

192204
class MyHandler(rpc.RPCHandler):
@@ -229,7 +241,7 @@ def runcode(self, code):
229241
exec code in self.locals
230242
except:
231243
if quitting:
232-
sys.exit(0)
244+
exit()
233245
# even print a user code SystemExit exception, continue
234246
print_exception()
235247
else:

0 commit comments

Comments
 (0)