-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmagic.py
More file actions
35 lines (30 loc) · 987 Bytes
/
magic.py
File metadata and controls
35 lines (30 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# slmagic.py
# This module switches a threaded program to a tasklet based one.
import runpy
import sys
from .monkeypatch import patch_all
from .app import install_stackless
import stackless
from . import main
# The actual __main__ will be run here in a tasklet
def run():
try:
# Shift command line arguments.
if len(sys.argv) > 1:
target = sys.argv.pop(1)
if target == "-m" and len(sys.argv) > 1:
#support the -m syntax after "magic"
target = sys.argv.pop(1)
runpy.run_module(target, run_name="__main__", alter_sys=True)
else:
runpy.run_path(target, run_name="__main__")
except Exception:
main.mainloop.exception = sys.exc_info()
raise
finally:
main.mainloop.running = False
if __name__ == "__main__":
patch_all()
install_stackless()
stackless.tasklet(run)()
main.mainloop.run()