[Twisted-Python] spawnProcess with timeout and same error handling on Unix and Windows
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Wed Sep 3 12:07:03 MDT 2014
On 05:17 pm, adi at roiban.ro wrote:
>On 3 September 2014 16:49, Adi Roiban <adi at roiban.ro> wrote:
>>Hi,
>>
>>If I call spawnProcess with a bad executable, on Unix the process will
>>exit with exit code 1 while on Windows an OSError is raised.
>>
>>I am working on a multi-OS software and to make my life easier I ended
>>up with this hack inspired by _BackRelay
>>
>>https://gist.github.com/adiroiban/bac493f00ce5e94738ce
>>
>>----
>>
>>Is there something already in Twisted doing this? Am I reinventing the
>>wheel?
>>
>>If not, do you think that it would help to update _BackRelay to
>>support timeout and cross-os error handling?
>
>Searching the Twisted trac I found this ticket
>http://twistedmatrix.com/trac/ticket/4184
>
>Maybe we can leave spawnProcess as the low-level API and then create
>another wrapper which will handle/raise the errors in an consistent
>way.
>
>For the case where command is not found, I prefer the behaviour from
>Windows where an OSError is raise, rather than
>looking at errReceived and trying to guess is execvpe call failed or
>not.
It is more convenient, certainly. Unfortunately on POSIX the underlying
API isn't synchronous - which is why the POSIX implementation doesn't
deliver the exception synchronously. So to be uniform we probably need
to make the Windows behavior asynchronous.
I suggest we can improve the situation by reporting the error more in an
easier-to-recognize way when we report it asynchronously, though.
For example, instead of forcing the application to parse stderr we could
deliver a different exception type to processEnded.
A better solution would be to make `spawnProcess` properly asynchronous
- have it return a `Deferred` that fires with an `IProcessTransport` and
let that `Deferred` fire with a `Failure` if there is a problem creating
the new process.
But that's probably more like "introduce an API to replace
`spawnProcess`" (for which I believe there is also a ticket).
Jean-Paul
More information about the Twisted-Python
mailing list