Show More
@@ -1,70 +1,74 b'' | |||||
1 | """toplevel setup/teardown for parallel tests.""" |
|
1 | """toplevel setup/teardown for parallel tests.""" | |
2 |
|
2 | |||
3 | #------------------------------------------------------------------------------- |
|
3 | #------------------------------------------------------------------------------- | |
4 | # Copyright (C) 2011 The IPython Development Team |
|
4 | # Copyright (C) 2011 The IPython Development Team | |
5 | # |
|
5 | # | |
6 | # Distributed under the terms of the BSD License. The full license is in |
|
6 | # Distributed under the terms of the BSD License. The full license is in | |
7 | # the file COPYING, distributed as part of this software. |
|
7 | # the file COPYING, distributed as part of this software. | |
8 | #------------------------------------------------------------------------------- |
|
8 | #------------------------------------------------------------------------------- | |
9 |
|
9 | |||
10 | #------------------------------------------------------------------------------- |
|
10 | #------------------------------------------------------------------------------- | |
11 | # Imports |
|
11 | # Imports | |
12 | #------------------------------------------------------------------------------- |
|
12 | #------------------------------------------------------------------------------- | |
13 |
|
13 | |||
|
14 | import os | |||
14 | import tempfile |
|
15 | import tempfile | |
15 | import time |
|
16 | import time | |
16 | from subprocess import Popen, PIPE, STDOUT |
|
17 | from subprocess import Popen, PIPE, STDOUT | |
17 |
|
18 | |||
|
19 | from IPython.utils.path import get_ipython_dir | |||
18 | from IPython.parallel import Client |
|
20 | from IPython.parallel import Client | |
19 |
|
21 | |||
20 | processes = [] |
|
22 | processes = [] | |
21 | blackhole = tempfile.TemporaryFile() |
|
23 | blackhole = tempfile.TemporaryFile() | |
22 |
|
24 | |||
23 | # nose setup/teardown |
|
25 | # nose setup/teardown | |
24 |
|
26 | |||
25 | def setup(): |
|
27 | def setup(): | |
26 | cp = Popen('ipcontroller --profile iptest -r --log-level 10 --log-to-file'.split(), stdout=blackhole, stderr=STDOUT) |
|
28 | cp = Popen('ipcontroller --profile iptest -r --log-level 10 --log-to-file'.split(), stdout=blackhole, stderr=STDOUT) | |
27 | time.sleep(1) |
|
29 | engine_json = os.path.join(get_ipython_dir(), 'cluster_iptest', 'security', 'ipcontroller-engine.json') | |
|
30 | client_json = os.path.join(get_ipython_dir(), 'cluster_iptest', 'security', 'ipcontroller-client.json') | |||
|
31 | while not os.path.exists(engine_json) and not os.path.exists(client_json): | |||
|
32 | time.sleep(0.1) | |||
28 | processes.append(cp) |
|
33 | processes.append(cp) | |
29 | time.sleep(.5) |
|
|||
30 | add_engines(1) |
|
34 | add_engines(1) | |
31 | c = Client(profile='iptest') |
|
35 | c = Client(profile='iptest') | |
32 | while not c.ids: |
|
36 | while not c.ids: | |
33 | time.sleep(.1) |
|
37 | time.sleep(.1) | |
34 | c.spin() |
|
38 | c.spin() | |
35 | c.close() |
|
39 | c.close() | |
36 |
|
40 | |||
37 | def add_engines(n=1, profile='iptest'): |
|
41 | def add_engines(n=1, profile='iptest'): | |
38 | rc = Client(profile=profile) |
|
42 | rc = Client(profile=profile) | |
39 | base = len(rc) |
|
43 | base = len(rc) | |
40 | eps = [] |
|
44 | eps = [] | |
41 | for i in range(n): |
|
45 | for i in range(n): | |
42 | ep = Popen(['ipengine']+ ['--profile', profile, '--log-level', '10', '--log-to-file'], stdout=blackhole, stderr=STDOUT) |
|
46 | ep = Popen(['ipengine']+ ['--profile', profile, '--log-level', '10', '--log-to-file'], stdout=blackhole, stderr=STDOUT) | |
43 | # ep.start() |
|
47 | # ep.start() | |
44 | processes.append(ep) |
|
48 | processes.append(ep) | |
45 | eps.append(ep) |
|
49 | eps.append(ep) | |
46 | while len(rc) < base+n: |
|
50 | while len(rc) < base+n: | |
47 | time.sleep(.1) |
|
51 | time.sleep(.1) | |
48 | rc.spin() |
|
52 | rc.spin() | |
49 | rc.close() |
|
53 | rc.close() | |
50 | return eps |
|
54 | return eps | |
51 |
|
55 | |||
52 | def teardown(): |
|
56 | def teardown(): | |
53 | time.sleep(1) |
|
57 | time.sleep(1) | |
54 | while processes: |
|
58 | while processes: | |
55 | p = processes.pop() |
|
59 | p = processes.pop() | |
56 | if p.poll() is None: |
|
60 | if p.poll() is None: | |
57 | try: |
|
61 | try: | |
58 | p.terminate() |
|
62 | p.terminate() | |
59 | except Exception, e: |
|
63 | except Exception, e: | |
60 | print e |
|
64 | print e | |
61 | pass |
|
65 | pass | |
62 | if p.poll() is None: |
|
66 | if p.poll() is None: | |
63 | time.sleep(.25) |
|
67 | time.sleep(.25) | |
64 | if p.poll() is None: |
|
68 | if p.poll() is None: | |
65 | try: |
|
69 | try: | |
66 | print 'killing' |
|
70 | print 'killing' | |
67 | p.kill() |
|
71 | p.kill() | |
68 | except: |
|
72 | except: | |
69 | print "couldn't shutdown process: ", p |
|
73 | print "couldn't shutdown process: ", p | |
70 |
|
74 |
General Comments 0
You need to be logged in to leave comments.
Login now