From c4d24a03d15dfdf3a3f3ef6550f591ff2bae8b89 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 22 Sep 2019 19:54:23 +0200 Subject: [PATCH] Catch tracebacks when leaving the py console with exit/exit() --- evennia/commands/default/system.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/evennia/commands/default/system.py b/evennia/commands/default/system.py index fded209d90..41490b6502 100644 --- a/evennia/commands/default/system.py +++ b/evennia/commands/default/system.py @@ -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