Catch tracebacks when leaving the py console with exit/exit()

This commit is contained in:
Griatch 2019-09-22 19:54:23 +02:00
parent 22e87ba6db
commit c4d24a03d1

View file

@ -264,6 +264,7 @@ class EvenniaPythonConsole(code.InteractiveConsole):
"""Push some code, whether complete or not."""
old_stdout = sys.stdout
old_stderr = sys.stderr
class FakeStd:
def __init__(self, caller):
self.caller = caller
@ -274,9 +275,14 @@ class EvenniaPythonConsole(code.InteractiveConsole):
fake_std = FakeStd(self.caller)
sys.stdout = fake_std
sys.stderr = fake_std
result = super().push(line)
sys.stdout = old_stdout
sys.stderr = old_stderr
result = None
try:
result = super().push(line)
except SystemExit:
pass
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
return result