Skip to content

Commit 015651c

Browse files
quit() and exit() properly quit
--HG-- branch : scroll-frontend
1 parent c0fcdba commit 015651c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

bpython/scrollfrontend/coderunner.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
class SigintHappened(object):
99
pass
1010

11+
class SystemExitFromCodeThread(SystemExit):
12+
pass
13+
1114
class CodeRunner(object):
1215
"""Runs user code in an interpreter, taking care of stdout/in/err"""
1316
def __init__(self, interp=None, stuff_a_refresh_request=lambda:None):
@@ -71,6 +74,9 @@ def run_code(self, for_code=None):
7174
signal.signal(signal.SIGINT, self.orig_sigint_handler)
7275
self.orig_sigint_handler = None
7376
return request
77+
elif request in ['SystemExit']:
78+
self._unload_code()
79+
raise SystemExitFromCodeThread()
7480
else:
7581
raise ValueError("Not a valid request_from_code_thread value: %r" % request)
7682

@@ -83,7 +89,11 @@ def sigint_handler(self, *args):
8389
self.sigint_happened = True
8490

8591
def _blocking_run_code(self):
86-
unfinished = self.interp.runsource(self.source)
92+
try:
93+
unfinished = self.interp.runsource(self.source)
94+
except SystemExit:
95+
self.requests_from_code_thread.put('SystemExit')
96+
return
8797
self.requests_from_code_thread.put('unfinished' if unfinished else 'done')
8898

8999
def wait_and_get_value(self):

0 commit comments

Comments
 (0)