I'm using twisted to spawn a local process, which may be terminated in some condition.
I have a custom twisted.internet.protocol.ProcessProtocol
class for the reactor. If the local process abruptly terminated, I can't get the return value in processEnded
. The exitCode
is set to None
.
A mcv example is like this:
from twisted.internet import error,protocol,reactor
class MyPP(protocol.ProcessProtocol):
def processEnded(self, reason):
if reason.check(error.ProcessTerminated):
err_info = "wrong termination: %s; exitCode: %s; signal: %s" % \
(reason, reason.value.exitCode, reason.value.signal)
print(err_info)
else:
print("processEnded, status %d" % (reason.value.exitCode,))
print("quitting")
reactor.stop()
pp = MyPP()
reactor.spawnProcess(pp, "throw_exception", ["throw_exception"], {})
reactor.run()
And the throw_exception
executable could be compiled from:
#include <iostream>
int main() {
throw std::runtime_error("some exception");
return 0;
}
Execute the python example will print
wrong termination: [Failure instance: Traceback (failure with no frames): : A process has ended with a probable error condition: process ended by signal 6. ]; exitCode: None; signal: 6
The C++ example will have a return value of 134 if run in a shell, which means SIGABRT
(6) sent. (I've also tested sending SIGINT
to terminate and still getting no exit code.)
How can I get it in the ProcessProtocal
instance? Or it is impossible?