Catch tracebacks when leaving the py console with exit/exit()
This commit is contained in:
parent
a315b3c7ec
commit
f7ed56dc64
1 changed files with 9 additions and 3 deletions
|
|
@ -264,6 +264,7 @@ class EvenniaPythonConsole(code.InteractiveConsole):
|
||||||
"""Push some code, whether complete or not."""
|
"""Push some code, whether complete or not."""
|
||||||
old_stdout = sys.stdout
|
old_stdout = sys.stdout
|
||||||
old_stderr = sys.stderr
|
old_stderr = sys.stderr
|
||||||
|
|
||||||
class FakeStd:
|
class FakeStd:
|
||||||
def __init__(self, caller):
|
def __init__(self, caller):
|
||||||
self.caller = caller
|
self.caller = caller
|
||||||
|
|
@ -274,9 +275,14 @@ class EvenniaPythonConsole(code.InteractiveConsole):
|
||||||
fake_std = FakeStd(self.caller)
|
fake_std = FakeStd(self.caller)
|
||||||
sys.stdout = fake_std
|
sys.stdout = fake_std
|
||||||
sys.stderr = fake_std
|
sys.stderr = fake_std
|
||||||
result = super().push(line)
|
result = None
|
||||||
sys.stdout = old_stdout
|
try:
|
||||||
sys.stderr = old_stderr
|
result = super().push(line)
|
||||||
|
except SystemExit:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
sys.stdout = old_stdout
|
||||||
|
sys.stderr = old_stderr
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue