[Twisted-Python] How to force synchronous behavior

Pedro Sanchez psanchez at nortel.com
Mon Oct 31 08:28:39 EST 2005


I am the original poster of this thread. First of all, thank you for the 
different responses. However I still don't have a clear answer (other 
than what I'm thinking of doing is wrong, which is OK, it can be fixed).

I'm working on a Twisted/Nevow application, and yes, I'm new to both and 
I can tell that if learning Twisted has a step curve, doing it in 
conjuction with Nevow is really almost vertical. But, nevertheless, my 
application is working well these days.

The motivation for my question is the following: I added the 
guard/credentials stuff to my application. The issue is that in order to 
accept a login my application requires several things to happen before 
access can be granted. I therefore implemented my own AuthChecker() 
which fires several deferreds to acomplish its task. This is working 
well, including the use of deferToThread() in several places.

But, the behavior of the authentication wrapper is synchronous. That is, 
access to the system cannot be granted until all deferred operations 
have happended. In this wrapper I have something like:

     def requestAvatar(self, avatarId, mind, *interfaces):
         for iface in interfaces:
             if iface is inevow.IResource:
                 if avatarId is checkers.ANONYMOUS:
                     resc = login.LoginPage()
                     resc.realm = self
                     return (inevow.IResource, resc, noLogout)
                 else:
                     resc = home.RootPage()
                     resc.realm = self
                     return (inevow.IResource, resc,
                             self.createLogout(avatarId, mind))
             else:
                 raise NotImplementedError("Not supported.")

So let me rephrase my original question. Given that the real user 
authentication is happening in my AuthChecker() implemented somewhere 
else, with deferreds and what not, how can I force this requestAvatar() 
thing to wait until the whole login process has finished? My idea was to 
force a synchronous behavior on AuthChecker() forcing this way the login 
process to wait for it to finish.

While writting this I realize that I may be missunderstanding how the 
credentials stuff works ... who knows.

Any suggestions are appreciated,

Thank you,

-- 
Pedro






More information about the Twisted-Python mailing list