def makeDeferredWithProcessProtocol():
"""Returns a (`Deferred`, `ProcessProtocol`) tuple.
The Deferred's `callback()` will be called (with None) if the
`ProcessProtocol` is called back indicating that no error occurred.
Its `errback()` will be called with the `Failure` reason otherwise.
"""
done = Deferred()
protocol = ProcessProtocol()
# Call the errback if the "failure" object indicates a non-zero exit.
protocol.processEnded = lambda reason: (
done.errback(reason) if (reason and not reason.check(ProcessDone))
else done.callback(None))
return done, protocol
评论列表
文章目录