If the code includes sys.exit or raise SystemExit, it won't get caught here:
https://github.com/jataware/archytas/blob/main/archytas/python.py#L54
and it'll kill the whole process.
ChatGPT says the solution is
try:
exec(script, self.locals)
except BaseException as e: # catches SystemExit too
if isinstance(e, SystemExit):
code = e.code if e.code is not None else 0
exception_info = {
"type": "SystemExit",
"message": f"exit({code})",
"traceback": traceback.format_exc(),
"code": code,
}
else:
exception_info = {
"type": type(e).__name__,
"message": str(e),
"traceback": traceback.format_exc(),
}
ChatGPT also says that this won't catch os._exit, which would need to be monkey-patched like
import os, types
def _blocked__exit(code=0):
raise SystemExit(code) # or a custom exception you handle
# Before exec:
safe_os = types.SimpleNamespace(**{k: getattr(os, k) for k in dir(os) if not k.startswith("_")})
safe_os._exit = _blocked__exit
self.locals.setdefault("os", safe_os)
If the code includes
sys.exitorraise SystemExit, it won't get caught here:https://github.com/jataware/archytas/blob/main/archytas/python.py#L54
and it'll kill the whole process.
ChatGPT says the solution is
ChatGPT also says that this won't catch
os._exit, which would need to be monkey-patched like