Use explicit locals for custom script execution, handle exception in similar fashion as Python

This commit is contained in:
Lukas Raska 2022-07-28 08:10:52 +02:00 committed by Megan Wilhite
parent 6d580d24ed
commit 9f9cb2f57a

10
run.py
View file

@ -65,9 +65,13 @@ def python_runtime():
# update passed args so they don't start with "<binary> python"
sys.argv = sys.argv[2:]
with open(script) as f:
exec(f.read())
exec_locals = {"__name__": "__main__", "__file__": str(script), "__doc__": None}
with open(script, encoding="utf-8") as rfh:
try:
exec(rfh.read(), exec_locals)
except Exception:
traceback.print_exc()
sys.exit(1)
def redirect(argv):