Python: CG trace: Handle SystemExit

otherwise, with-exit would end the tracer without producing any output :|
This commit is contained in:
Rasmus Wriedt Larsen
2020-07-21 19:40:58 +02:00
parent 296d7d1725
commit 290eb638f9
2 changed files with 9 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
import sys
print("will exit now")
sys.exit()

View File

@@ -173,12 +173,15 @@ class CallGraphTracer:
try:
sys.setprofile(self.profilefunc)
exec(code, globals, locals)
sys.setprofile(None)
return "completed"
except SystemExit:
return "completed (SystemExit)"
except Exception:
sys.setprofile(None)
LOGGER.info("Exception occurred while running program:", exc_info=True)
return "exception occurred"
finally:
sys.setprofile(None)
def profilefunc(self, frame: FrameType, event: str, arg):
# ignore everything until the first call, since that is `exec` from the `run`