[Twisted-Python] Knowing whether spawnProcess did anything useful

Dominic van Berkel dominic at baudvine.net
Tue Jul 13 17:18:10 EDT 2010


I'm looking for a way to know whether spawnProcess() did anything
useful.  That is, whether anything has actually been executed. In my
specific case the executables are all persistent (pluggable modules,
they stick around for a while) so based on the following snippet I
thought I could check whether the resulting ProcessTransport has a pid:

"From before IProcessProtocol.makeConnection is called to before
IProcessProtocol.processEnded is called, pid is an int giving the
platform process ID of this process. pid is None at all other times."[1]

However, a quick tour on the REPL shows otherwise (than I expected, not
necessarily otherwise than what the docs say):

>>> from twisted.internet import reactor
>>> from twisted.internet import protocol
>>> p = protocol.ProcessProtocol()
>>> f = reactor.spawnProcess(p, "fail", ["fail"])
>>> f
<Process pid=21053 status=-1>
>>> f.pid

I thought status might be of some relevance, but it didn't really change
when I gave it a shot with actual executables.

Something tells me I'm being massively stupid here, but I'm genuinely
stuck.  Can't really believe that there's no way to do this, though.



Dominic van Berkel
"You don't have conversations with microprocessors. You tell them what
to do, then helplessly watch the disaster when they take you literally."
- David Brin, Startide Rising

More information about the Twisted-Python mailing list