[Twisted-Python] RE: waiting on transport return

jmbenski at micron.com jmbenski at micron.com
Fri Dec 9 13:02:03 EST 2005

I guess I'm still trying to wrap my head around deferreds and how best to use them as they were intended.  The way that code works, I have to pass my deferred chain to sendCommand.  The protocol needs to store that deferred on its deferred stack, so that I can pass the results of the command back to the deferred function.

After looking at the code a bit more and your change below, I'm surprised that my code works.  Why isn't the reactor kicking off my deferreds that are stored in the queue?  My current logic is dependent on the protocol running the commandComplete function before the deferreds fire in the protocol's deferred queue.  

#Do some thing
#Send the command
#Do some more
#return control to the reactor

??Here the reactor should kick off my command and run any deferreds.

Am I just lucky that my server returns the response(commandComplete) before the deferreds in the queue fire?  The return of the data and the chain of deferreds are not linked in any way, which I guess is what my original question is.  How can my commandComplete return a deferred and kick off a logic chain?  How is it working now?

-----Original Message-----
From: twisted-python-bounces at twistedmatrix.com [mailto:twisted-python-bounces at twistedmatrix.com] On Behalf Of Jean-Paul Calderone
Sent: Friday, December 09, 2005 10:01 AM
To: Twisted general discussion
Subject: RE: [Twisted-Python] RE: waiting on transport return

On Fri, 9 Dec 2005 09:03:52 -0700, jmbenski at micron.com wrote:
>I'm not trying to bump my question, but if someone could tell me if I'm just being stupid and missing something with this code or that it isn't possible to do what I need with a spawned process?  If I know it isn't possible, I can just continue down the path I am.  It's not too much of a pain, but it just feels...wrong.

The code mostly seems good to me.  The only thing I might change is 
completely trivial: instead of passing a Deferred in to sendCommand, 
I'd have sendCommand be responsible for creating the Deferred and 
then return it, so your application code would look like this - 

  d = self.processprotocol.sendCommand("syncCmd", cmd)

I'm not sure from where your unhappyness with the version you posted 
stems, so I'm not sure what other comments to make.


Twisted-Python mailing list
Twisted-Python at twistedmatrix.com

More information about the Twisted-Python mailing list