-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·36 lines (27 loc) · 894 Bytes
/
run
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
36
#!/usr/bin/env python
# Quick and dirty convenient script to run the example
import sys
from twisted.python.reflect import namedModule
from twisted.internet import reactor
import csp
def run_twisted_then_call(main):
def run_main():
channel = csp.go_channel(main)
value = yield csp.take(channel)
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "main returned", value
reactor.stop()
reactor.callWhenRunning(lambda: csp.go(run_main))
reactor.run()
if __name__ == "__main__":
args = sys.argv[1:]
if not args:
print "Module name required"
exit(1)
module_name = args[0]
module = namedModule(module_name)
main = getattr(module, "main", None)
if main is None:
print "No main function found in module %s" % module_name
exit(2)
run_twisted_then_call(main)