__init__.py
69 lines
| 1.9 KiB
| text/x-python
|
PythonLexer
MinRK
|
r3637 | """toplevel setup/teardown for parallel tests.""" | ||
MinRK
|
r3664 | #------------------------------------------------------------------------------- | ||
# Copyright (C) 2011 The IPython Development Team | ||||
# | ||||
# Distributed under the terms of the BSD License. The full license is in | ||||
# the file COPYING, distributed as part of this software. | ||||
#------------------------------------------------------------------------------- | ||||
#------------------------------------------------------------------------------- | ||||
# Imports | ||||
#------------------------------------------------------------------------------- | ||||
MinRK
|
r3654 | import tempfile | ||
MinRK
|
r3595 | import time | ||
MinRK
|
r3654 | from subprocess import Popen, PIPE, STDOUT | ||
MinRK
|
r3595 | |||
MinRK
|
r3666 | from IPython.parallel import client | ||
MinRK
|
r3595 | |||
MinRK
|
r3637 | processes = [] | ||
MinRK
|
r3654 | blackhole = tempfile.TemporaryFile() | ||
MinRK
|
r3637 | |||
# nose setup/teardown | ||||
MinRK
|
r3595 | |||
def setup(): | ||||
MinRK
|
r3658 | cp = Popen('ipcontrollerz --profile iptest -r --log-level 10 --log-to-file'.split(), stdout=blackhole, stderr=STDOUT) | ||
MinRK
|
r3637 | processes.append(cp) | ||
time.sleep(.5) | ||||
MinRK
|
r3664 | add_engines(1) | ||
MinRK
|
r3655 | c = client.Client(profile='iptest') | ||
while not c.ids: | ||||
time.sleep(.1) | ||||
c.spin() | ||||
MinRK
|
r3664 | c.close() | ||
MinRK
|
r3595 | |||
MinRK
|
r3664 | def add_engines(n=1, profile='iptest'): | ||
rc = client.Client(profile=profile) | ||||
base = len(rc) | ||||
eps = [] | ||||
for i in range(n): | ||||
ep = Popen(['ipenginez']+ ['--profile', profile, '--log-level', '10', '--log-to-file'], stdout=blackhole, stderr=STDOUT) | ||||
# ep.start() | ||||
processes.append(ep) | ||||
eps.append(ep) | ||||
while len(rc) < base+n: | ||||
time.sleep(.1) | ||||
rc.spin() | ||||
rc.close() | ||||
return eps | ||||
MinRK
|
r3595 | |||
def teardown(): | ||||
time.sleep(1) | ||||
while processes: | ||||
p = processes.pop() | ||||
if p.poll() is None: | ||||
try: | ||||
p.terminate() | ||||
except Exception, e: | ||||
print e | ||||
pass | ||||
if p.poll() is None: | ||||
time.sleep(.25) | ||||
if p.poll() is None: | ||||
try: | ||||
print 'killing' | ||||
p.kill() | ||||
except: | ||||
MinRK
|
r3655 | print "couldn't shutdown process: ", p | ||
MinRK
|
r3595 | |||