[Twisted-Python] newbie question about using deferreds

Martin Waite martin at datacash.com
Wed Mar 5 04:34:27 EST 2003


Twisted newbie here with a plan. Could
someone please tell me if I'm barking up trees here ?

In my application, I want to run a Twisted listener
that collects incoming request messages and passes these to a 
thread that posts the message into a queue table in a database.
Another thread polls the database for responses, and 
distributes these to the connections that made the corresponding

My understanding is that somehow I can do this using the Deferred
mechanism - only I'm not sure how.

My plan is to keep a global hash table of RequestID -> Deferred.
When the listener identifies the end of a request, a deferred is 
created and stored against the RequestID.  When the thread polling
for responses from the database gets a response, it looks for 
a matching deferred from the global hash table and then somehow
activates the deferred.

Is this sane or am I missing an easier way to do this ?


More information about the Twisted-Python mailing list