[Twisted-Python] How to force synchronous behavior
Pedro Sanchez
psanchez at nortel.com
Mon Oct 31 08:51:16 MST 2005
Stefan Behnel wrote:
> Ah, there we go. This simplifies to
>
> def registerSession(self, session):
> def _customerInit(self, customer):
> ...
> session.customerInit = True
>
> # initialize customer data
> d1 = defer.maybeDeferred(customerInit, session)
> d1.addCallback(_customerInit)
> d1.addErrback(errhandler, session)
> return d1
>
> And then everyone who calls registerSession() receives a Deferred and can add
> callbacks for whatever else needs to be done after the session is successfully
> registered and _customerInit has been run. You get the difference? The
> registration is not done when registerSession /returns/, but when the Deferred
> that it returns /fires/. So keep adding callbacks to that Deferred instead of
> expecting things to have terminated. Twisted will then take care of running
> everything in a chain.
>
> Stefan
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
Yes, I understand that very well. The problem is (was, I guess) my wrong
assumption that the requestAvatar function (which at the end is the
"caller" of registerSession() in my actual code) was supposed to be
synchronous and not to deal with deferreds at all.
Thanks,
--
Pedro
More information about the Twisted-Python
mailing list