ncolony/schedulelib.py
def runProcess(args, timeout, grace, reactor):
    """Run a process, return a deferred that fires when it is done

    :params args: Process arguments
    :params timeout: Time before terminating process
    :params grace: Time before killing process after terminating it
    :params reactor: IReactorProcess and IReactorTime
    :returns: deferred that fires with success when the process ends,
              or fails if there was a problem spawning/terminating
              the process
    """
    deferred = defer.Deferred()
    protocol = ProcessProtocol(deferred)
    process = reactor.spawnProcess(protocol, args[0], args, env=os.environ)

    def _logEnded(err):
        err.trap(tierror.ProcessDone, tierror.ProcessTerminated)
        print(err.value)
    deferred.addErrback(_logEnded)

    def _cancelTermination(dummy):
        for termination in terminations:
            if termination.active():
                termination.cancel()
    deferred.addCallback(_cancelTermination)
    terminations = []
    terminations.append(reactor.callLater(timeout, process.signalProcess,
                                          "TERM"))
    terminations.append(reactor.callLater(timeout+grace,
                                          process.signalProcess, "KILL"))
    return deferred
def runProcess(args, timeout, grace, reactor):
    deferred = defer.Deferred()
    protocol = ProcessProtocol(deferred)
    process = reactor.spawnProcess(protocol, args[0], args, env=os.environ)

    def _logEnded(err):
        err.trap(tierror.ProcessDone, tierror.ProcessTerminated)
        print(err.value)
    deferred.addErrback(_logEnded)

    def _cancelTermination(dummy):
        for termination in terminations:
            if termination.active():
                termination.cancel()
    deferred.addCallback(_cancelTermination)
    terminations = []
    terminations.append(reactor.callLater(timeout, process.signalProcess,
                                          "TERM"))
    terminations.append(reactor.callLater(timeout+grace,
                                          process.signalProcess, "KILL"))
    return deferred
def runProcess ( args , timeout , grace , reactor ) : deferred = defer . Deferred ( ) protocol = ProcessProtocol ( deferred ) process = reactor . spawnProcess ( protocol , args [ 0 ] , args , env = os . environ ) def _logEnded ( err ) : err . trap ( tierror . ProcessDone , tierror . ProcessTerminated ) print ( err . value ) deferred . addErrback ( _logEnded ) def _cancelTermination ( dummy ) : for termination in terminations : if termination . active ( ) : termination . cancel ( ) deferred . addCallback ( _cancelTermination ) terminations = [ ] terminations . append ( reactor . callLater ( timeout , process . signalProcess , "TERM" ) ) terminations . append ( reactor . callLater ( timeout + grace , process . signalProcess , "KILL" ) ) return deferred
Run a process, return a deferred that fires when it is done

    :params args: Process arguments
    :params timeout: Time before terminating process
    :params grace: Time before killing process after terminating it
    :params reactor: IReactorProcess and IReactorTime
    :returns: deferred that fires with success when the process ends,
              or fails if there was a problem spawning/terminating
              the process
Run a process return a deferred that fires when it is done