[Twisted-Python] Improving spawnProcess and friends
naked at iki.fi
Wed Jul 19 04:09:35 EDT 2006
I'd like to write an improvement to spawnProcess - but I thought I
should check with the devs here first to get comments and to see if it
would be something that could be merged to the mainline at some point.
The primary thing I want to do is to improve the childFDs
handling. Instead of the childFDs being a dictionary, I'd like to make
it be an object that is set up beforehand.
In addition to the current functionality of duplicating one of the
parent's fds and providing simple pipes, I'd like to add features to
configure arbitrary PTYs to be set up, for socketpairs to be set up
and to allow the duplication of some pipe into multiple child fds. To
clarify a bit, I'd like for a way to be able to start a process and
say that a socketpair should be created, it should be dup'd to fd 0
and fd 1 on the child and a pipe should be created for reading and it
should be dup'd to fd 2 on the child. The same with PTYs as well, so
this change would unify Process and PTYProcess.
Also, I would want to make it possible for each created reader,
writer, PTY, socketpair, whatever to have a separate protocol. That
is, I want to be able to say that this PTY should be handled by my
protocol here that inherits from LineReceiver - instead of having to
implement all of those in the ProcessProtocol.
Backwards compatibility would be obtained by still allowing the dict
type in childFDs and just mapping them to the new object inside
spawnProcess. Also the custom protocols would be optional and the
default protocol would just call childDataReceived and
childConnectionLost on the ProcessProtocol.
The other feature I would like to implement while mucking around with
the process module is the preexec_fn feature of the subprocess
module. That is, a function that gets executed just before the child
is exec'd. There can probably be other uses for this as well, but the
main usage for this would be a chroot call. I'm considering if it
should be a list of functions executed in order - since there might be
a need to do a chroot, a chdir and another chroot or something similar
- but of course the user can just supply a function that does that.
The actual API for these isn't finalized, I was thinking of making it
up as I go and seeing how it turns out.
So, what do you think?
PS. I'm Hadaka in #twisted at OPN - just to make the connection in case
you've seen me.
More information about the Twisted-Python