[Twisted-Python] Deferred usage clarification andrew-twisted at
puzzling.org Sun Jun 1 20:31:39 EDT 2003 On Sun, Jun 01, 2003 at
08:05:02PM -0400, Gary Poster wrote: > Hi. A newbie question:
I'd like a bit of clarification in Deferred > usage. More
specifically, it would be nice if one of the examples on > the
Twisted Deferred howto page used a real blocking call rather
than a > So, to see if I'm on the right track, I'd like to
modify the third code > example to use a sleep, to make it
better parallel the first code > snippet on the howto page. >
First, here it is from the page, without modification: > Here's
my modification. Is this the right usage? No -- see below. >
class Getter: > def getData(self, x): > # this won't block > d =
defer.Deferred() > reactor.callLater(0, self.doWork, x, d) >
return d > def doWork(self, x, deferred): > # churn, churn,
churn > deferred.callback(x * 3) You're misunderstanding the
purpose of Deferreds. They don't do any magic to make blocking
calls happen asynchronously. A Defer