[Twisted-Python] newbie question about using deferreds
radix at twistedmatrix.com
Wed Mar 5 05:04:20 EST 2003
On Wed, Mar 05, 2003 at 09:34:27AM +0000, Martin Waite wrote:
> 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 ?
Mapping of RID:Deferred is quite sane, I think. It could probably
even be called an idiom, by now.
"somehow activates the Deferred" is just
self.requests[rid].callback(val), where self.requests is your mapping,
rid is the request ID, and val is the value that was recently made
Twisted | Christopher Armstrong: International Man of Twistery
Radix | Release Manager, Twisted Project
More information about the Twisted-Python