[Twisted-Python] Sane way to get the exit code from reactor.spawnProcess(SomeProtocol, ...)
Is there a more sane way to get the exit code from a ProcessProtocol than by parsing it out of reason.value in ProcessProtocol.processEnded()? I can't seem to find the error code by itself anywhere. (see example code at bottom) If I replace "print reason.value" with "print dir(reason)" below, then I get the following output for both successful and unsuccessful spawns: ['__doc__', '__getstate__', '__init__', '__module__', '__repr__', '__str__', '_findFailure', '_yieldOpcode', 'check', 'cleanFailure', 'count', 'frames', 'getBriefTraceback', 'getErrorMessage', 'getTraceback', 'getTracebackObject', 'parents', 'pickled', 'printBriefTraceback', 'printDetailedTraceback', 'printTraceback', 'raiseException', 'stack', 'tb', 'throwExceptionIntoGenerator', 'trap', 'type', 'value'] Most of the *Traceback functions include the "value" line inside them. getErrorMessage() apparently returns "value" itself. "value" looks like: "A process has ended without apparent errors: process finished with exit code 0." or "A process has ended with a probable error condition: process ended with exit code 1." ...but the actual exit code doesn't seep to appear (by itself) anywhere! ~ Nathan from twisted.internet import reactor from twisted.internet.protocol import ProcessProtocol class TestProtocol(ProcessProtocol): def processEnded(self, reason): print reason.value def good(): good_binary = "/bin/ls" good_args = ("/bin/ls", '/') good_process = reactor.spawnProcess(TestProtocol(), good_binary, args=good_args) def bad(): bad_binary = "/bad" bad_args = ("/bad", '/') bad_process = reactor.spawnProcess(TestProtocol(), bad_binary, args=bad_args) reactor.callWhenRunning(good) reactor.callLater(1.0, bad) reactor.callLater(2.0, reactor.stop) reactor.run()
On Tue, 2008-06-24 at 16:43 -0600, Nathan wrote:
Is there a more sane way to get the exit code from a ProcessProtocol than by parsing it out of reason.value in ProcessProtocol.processEnded()? I can't seem to find the error code by itself anywhere. (see example code at bottom)
If I replace "print reason.value" with "print dir(reason)" below, then I get the following output for both successful and unsuccessful spawns:
reason.value will be instance of ProcessExited or something (it's in twisted.internet.error), which should have exitCode attribute or something. Check the API reference for twisted.internet.error.
On Tue, Jun 24, 2008 at 5:39 PM, Itamar Shtull-Trauring <itamar@itamarst.org> wrote:
reason.value will be instance of ProcessExited or something (it's in twisted.internet.error), which should have exitCode attribute or something. Check the API reference for twisted.internet.error.
Ah, that's what I was missing. Since "print reason.value" spit out such a nice string, I falsely assumed it was just a string. reason.value.exitCode is what I was looking for. Thanks! ~ Nathan
participants (2)
-
Itamar Shtull-Trauring -
Nathan