[Twisted-Python] How to force synchronous behavior

Pedro Sanchez psanchez at nortel.com
Mon Oct 31 07:56:03 MST 2005


Stefan Behnel wrote:
> Pedro Sanchez wrote:
> 
>>But, the behavior of the authentication wrapper is synchronous. That is,
>>access to the system cannot be granted until all deferred operations
>>have happended.
> 
> 
> Maybe I'm underestimating your problem, but that sounds to me like Deferred
> chaining is all you need. Merge the pending Deferreds into a DeferredList and
> then append your login procedure to that.
> 
> Stefan
> 
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> 
I tried this already and couldn't make it work. In one of the functions 
called during the validation process I have this

     def registerSession(self, session):
         def _customerInit(self, customer):
            ...
            session.customerInit = True

         # initialize customer data
         d = defer.Deferred()
         d1 = defer.maybeDeferred(customerInit, session)
         d1.addCallback(_customerInit)
         d1.addErrback(errhandler, session)
         d.chainDeferred(d1)
         return d

customerInit() fires several deferreds which I collect with a 
deferredList already. This works well. My goal therefore is to force 
"registerSession()" to behave synchronously[1] so that whoever is 
invoking it will block. I thought that by defining my own deferred d, 
and that by chaining it to d1 I would achive this. But I don't, the 
caller still doesn't block and goes along thinking that 
registerSsession() is done. I guess I don't understand how to use the 
chainDeferred() call. Hints are welcome; regardeless of what I end up 
doing, I'd like to understand who deferred chaining works.

In a previous answer from Jean-Paul Calderone, he mentions that the 
requestAvatar and requestAvatarId methods don't have to be synchronous 
(thanks Jean-Paul!). This is no evident from the documentation, in fact, 
I dare to say that in all examples I've seen so far these calls are 
always synchronous, therefore my wrong assumption that they had to be.
This is likely the right way to go to modify my program. I'll look into it.

Thanks again!

-- 
Pedro



[1] Boy, I say this with hesitation after the long thread I spawned with 
my post, and after reading repeately that I shouldn't even attempt to do 
it. Which is fine, I take it, thanks for the imput. But I'm just trying 
to figure out the best way around it for my application.






More information about the Twisted-Python mailing list