Show More
@@ -0,0 +1,21 | |||||
|
1 | #!/usr/bin/env python | |||
|
2 | """Python wrapper around a submitted workflow job. | |||
|
3 | ||||
|
4 | In reality this would be a more sophisticated script, here we only illustrate | |||
|
5 | the basic idea by considering that a submitted 'job' is a Python string to be | |||
|
6 | executed. | |||
|
7 | """ | |||
|
8 | ||||
|
9 | import sys | |||
|
10 | ||||
|
11 | argv = sys.argv | |||
|
12 | ||||
|
13 | from IPython.zmq.parallel.engine import main | |||
|
14 | ||||
|
15 | ns = {} | |||
|
16 | ||||
|
17 | # job | |||
|
18 | exec sys.argv[1] in ns | |||
|
19 | ||||
|
20 | # start engine with job namespace | |||
|
21 | main([], user_ns=ns) |
@@ -0,0 +1,44 | |||||
|
1 | """Mock workflow manager. | |||
|
2 | ||||
|
3 | This is a mock work manager whose submitted 'jobs' simply consist of executing | |||
|
4 | a python string. What we want is to see the implementation of the ipython | |||
|
5 | controller part. | |||
|
6 | """ | |||
|
7 | ||||
|
8 | from __future__ import print_function | |||
|
9 | ||||
|
10 | import atexit | |||
|
11 | import sys | |||
|
12 | ||||
|
13 | from subprocess import Popen | |||
|
14 | ||||
|
15 | def cleanup(controller, engines): | |||
|
16 | """Cleanup routine to shut down all subprocesses we opened.""" | |||
|
17 | import signal, time | |||
|
18 | ||||
|
19 | print('Starting cleanup') | |||
|
20 | print('Stopping engines...') | |||
|
21 | for e in engines: | |||
|
22 | e.send_signal(signal.SIGINT) | |||
|
23 | print('Stopping controller...') | |||
|
24 | # so it can shut down its queues | |||
|
25 | controller.send_signal(signal.SIGINT) | |||
|
26 | time.sleep(0.1) | |||
|
27 | print('Killing controller...') | |||
|
28 | controller.kill() | |||
|
29 | print('Cleanup done') | |||
|
30 | ||||
|
31 | ||||
|
32 | if __name__ == '__main__': | |||
|
33 | ||||
|
34 | # Start controller in separate process | |||
|
35 | cont = Popen(['python', '-m', 'IPython.zmq.parallel.controller']) | |||
|
36 | print('Started controller') | |||
|
37 | ||||
|
38 | # "Submit jobs" | |||
|
39 | eng = [] | |||
|
40 | for i in range(4): | |||
|
41 | eng.append(Popen(['python', 'job_wrapper.py','x=%s' % i])) | |||
|
42 | ||||
|
43 | # Ensure that all subpro | |||
|
44 | atexit.register(lambda : cleanup(cont, eng)) |
General Comments 0
You need to be logged in to leave comments.
Login now