[Twisted-Python] Understanding the IOCP reactor and adding spawnProcess

Jp Calderone exarkun at divmod.com
Mon Jul 11 15:26:15 EDT 2005

On Mon, 11 Jul 2005 12:16:35 -0500, Justin Johnson <justinjohnson at gmail.com> wrote:
>On 7/11/05, Jp Calderone <exarkun at divmod.com> wrote:
> [snip]
>> 3. Notify the ProcessProtocol via protocol.makeConnection (not sure
>> > why, looking at win32eventreactor)
>> makeConnection is the method that's actually part of IProtocol (even
>> though ProcessProtocol doesn't implement IProtocol, it still adheres to its
>> API in this regard). Generally, all it does is set the .transport attribute
>> on the protocol instance and then call connectionMade. This might seem
>> pointless in the case of processes, but since it maintains consistency with
>> other kinds of transports, it is useful.
>  So the Process class is the transport? In win32eventreactor, 3 threads are
>started that loop on reading stdout and stderr and writing data from the
>outQueue to stdin. It seems to me that I would not use these threads, but
>instead have each of these 3 file handles associated with the IOCP. Then the
>methods defined in ops.py would be used to handle events on those handles,
>resulting in transport methods being called. These transport methods would
>be methods on the Process class, which would result in methods on a single
>instance of the ProcessProtocol being called. This single instance of the
>ProcessProtocol would be shared by all of the 3 file handles. Am I
>understanding correctly? Are write and loseConnection the only methods the
>Process would need to implement from ITransport?

That mostly sounds correct, except the last bit.  What makes it a transport is that it implements /all/ of ITransport.  Moreover, ProcessProtocols expect their transport to be an IProcessTransport, which adds several methods on top of ITransport.  Everything in each of those interfaces needs to be implemented.

For reference, <http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.ITransport.html> and <http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IProcessTransport.html>.


More information about the Twisted-Python mailing list