[Twisted-Python] Event Driven Programming 101 question

Steve Freitas sflist at ihonk.com
Sat Aug 2 04:37:00 MDT 2003


Hi all,

I've got a few questions about Deferreds. I understand the concept better, but 
I need a little help at the moment. It's apparent to me that a lot's going on 
behind the scenes between Deferreds and the Reactor, and that 
twisted.enterprise orchestrates things in a way I don't yet understand.

I'm looking at this from the perspective of my little XML-RPC server. A client 
hits a XML-RPC function, and by the time that function returns its value, it 
needs all its Deferreds to have generated their results. That leads to this 
question:

When is a Deferred guaranteed to have a result?

One answer could be, "When its callback gets called." And that would be true. 
But what if the function that gets the Deferred needs the result before it 
can move on? It seems like it'll get the Deferred and then go on its merry 
way, whether the Deferred has a result or not. And that's confusing to me, 
because I'm left wondering what happens if my database takes a long time to 
respond:

def xmlrpc_foo(self):
	result = dbpool.runQuery("select * from gigantic_table") # adbapi
	return result

In this case, what's it gonna be? A Deferred that's evaluated as None because 
Postgres is still churning, or is Twisted only going to let the code continue 
once the Deferred has a result?

Sorry if it seems I'm not making sense... Event-driven programming is new to 
me, but I'm a motivated learner. :-) (And if anybody knows of a good general 
guide to this paradigm, I'm all ears.)

Thanks for your help!

Steve




More information about the Twisted-Python mailing list