[Twisted-Python] Event Driven Programming 101 question

Uwe C. Schroeder uwe at oss4u.com
Sat Aug 2 11:35:55 EDT 2003


On Saturday 02 August 2003 03:37 am, Steve Freitas wrote:
> 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:

You write a chain of results: for example
[ abstract code ]

remotecall(mydatabase, getresultset1).addCallback(result1OK)

def result1OK(result):
	remotecall(get result based on result, result).addCallback(allOK)

def allOK(result):
    this is guaranteed to have the result


>
> 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
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

-- 
	UC

--
Open Source Solutions 4U, LLC	2570 Fleetwood Drive
Phone:  +1 650 872 2425		San Bruno, CA 94066
Cell:   +1 650 302 2405		United States
Fax:    +1 650 872 2417





More information about the Twisted-Python mailing list