import six
from subprocess import Popen, PIPE


def run_ipcluster(n=4):
    """Convenient way to start an ipcluster for testing.

    You have to wait for it to start, however.
    """
    # FIXME: This should be reimplemented to signal when the cluster has
    # successfully started
    if six.PY2:
        cmd = 'ipcluster'
    elif six.PY3:
        cmd = 'ipcluster3'
    else:
        raise NotImplementedError("Not run with Python 2 *or* 3?")

    engines = "--engines=MPIEngineSetLauncher"
    Popen([cmd, 'start', '-n', str(n), engines, str('&')],
           stdout=PIPE, stderr=PIPE)


if __name__ == '__main__':
    run_ipcluster()

@@ -1,12 +1,23 @@
+import sys%0A
 import six%0Af
@@ -56,29 +56,184 @@
 E%0A%0A%0A
-def run_ipcluster(n=4
+if six.PY2:%0A    ipcluster_cmd = 'ipcluster'%0Aelif six.PY3:%0A    ipcluster_cmd = 'ipcluster3'%0Aelse:%0A    raise NotImplementedError(%22Not run with Python 2 *or* 3?%22)%0A%0A%0Adef start(n=12
 ):%0A 
@@ -447,172 +447,8 @@
 rted
-%0A    if six.PY2:%0A        cmd = 'ipcluster'%0A    elif six.PY3:%0A        cmd = 'ipcluster3'%0A    else:%0A        raise NotImplementedError(%22Not run with Python 2 *or* 3?%22)
 %0A%0A  
@@ -503,16 +503,26 @@
  Popen(%5B
+ipcluster_
 cmd, 'st
@@ -604,51 +604,204 @@
 )%0A%0A%0A
-if __name__ == '__main__':%0A    run_ipcluster
+def stop():%0A    %22%22%22Convenient way to stop an ipcluster.%22%22%22%0A%0A    Popen(%5Bipcluster_cmd, 'stop'%5D, stdout=PIPE, stderr=PIPE)%0A%0A%0Aif __name__ == '__main__':%0A    cmd = sys.argv%5B1%5D%0A    fn = eval(cmd)%0A    fn
 ()%0A

Add a `stop` command to the script.