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