Exemple #1
0
def setupWhenReady(delay=3):
    """
    Wait until the control centre is running and set up all the stored configuration.

    :param delay: Seconds to wait between checking the control centre. (Optional).
    :type delay: ``int``

    """

    state  = controlcentre.runningState()

    # Only do something if it's starting or running.
    if state is True:
        _setupNow()
    elif state is None: # Starting
        Timer(interval=delay, function=setupWhenReady, args=[delay]).start()
Exemple #2
0
def issueControlCentreCommand(command, args=[], extraargs=[], afterwards=None):
    """
    Send a command to the command client and optionally run a function on finish.

    :param command: The command to run.
    :type command: ``str``
    :param args: List of arguments to the command. (optional)
    :type args: ``list(str)``
    :param extraargs: Arguments to the script, i.e. those beginning with "--". (optional)
    :type extraargs: ``dict``
    :param afterwards: The function to run afterwards (optional).
    :type afterwards: ``func``, takes the output file as a parameter. 
    :returns: ``True`` if the control centre is running, ``False`` otherwise.
    :rtype: ``bool``

    """

    if controlcentre.runningState() is not True:
        return False
  
    experiment_path = controlcentre.getExperimentPath()
    clientargs = __getCommandLineClientArgs()
    for arg in extraargs:
        clientargs.append(arg + "=" + extraargs[arg])
    clientargs.append(command)
    clientargs.extend(args)

    ioFile = open("/dev/null")
    try:
        ioFile = tempfile.SpooledTemporaryFile(256)
    except: pass # Ignore fuckups and use /dev/null instead

    command_process = subprocess.Popen(clientargs, cwd=getCommandLineClientPath(), stdout=ioFile, stderr=subprocess.STDOUT)

    if afterwards is not None:
        def _runWhenDone(process, func, io):
            if process.poll() is None:
                Timer(interval=1, function=_runWhenDone, args=[process, func, io]).start()
            else:
                func(io)
                io.close()

        _runWhenDone(command_process, afterwards, ioFile)

    return True
Exemple #3
0
def vazelsPhase():
    """
    Check the running status of vazels.

    :returns: The status. One of the values in :data:`Statuses`.
    :rtype: ``str``

    """

    global experiment_running_state
    global Statuses
  
    controlstat = controlcentre.runningState()

    if controlstat is False:
        return Statuses["STATUS_READY"]
  
    if controlstat is None:
        return Statuses["STATUS_STARTING"]

    if experiment_running_state is not None:
        return experiment_running_state
    else:
        return Statuses["STATUS_RUNNING"]