[Twisted-Python] newbie -- trying to do async ldap operations

Allan Streib astreib at indiana.edu
Tue Apr 22 19:19:28 EDT 2003


First to set my perspective -- I never heard of Twisted before two days
ago.

I have an XMLRPC server built with the Medusa framework.  I am looking at
moving the methods to Twisted in order to take advantage of Deferreds, SSL
support, and based on my brief exposure, the overall framework seems
cleaner.

This is a simplification, but to keep this short I have an XMLRPC method
that returns results from an LDAP search.  Currently the searches are
synchronous but they are fast enough that it has not been a problem.  Now
I need to expand the search filter options which will (could) result in a
slower search.

The OpenLDAP API (and python-ldap) supports asynchronus searching.  Sounds
perfect.  A call to ldap.search_s() returns a message ID which is later
used in a call to result() to get the results.  ldap.result() takes the
message ID, and a timeout argument which if zero is in effect a poll.

So what I want is for my XMLRPC method to invoke search_s and get the
message ID.  Then create a defered and provide its callback and the
message ID to something that will poll ldap.result() until it returns
results (if results are not ready it will return [None, None]) and then
pass those to the callback.  Here's where I get confused; I think the call
to ldap.result() needs to be done by reactor somehow since ldap.result()
may need to be called repeatedly before results are ready) but I'm not
sure.

The whole deferred light bulb has not quite come on for me yet, so I
appreciate any guidance.  The defer HOWTO examples all use something like
reactor.callLater() to represent a "delayed result" which is not really
helping me.  The XMLRPC example of returning a defered just returns
defer.succeed("hello"), again not quite a rich enough example.

I thought about adapting the adbapi stuff for LDAP, but the notion is in
my head that I should be able to do this without threads since the ldap
API supports async operations.

Many thanks,

Allan
-- 
"If you understand what you're doing, you're not learning anything"
                                             - Anon




More information about the Twisted-Python mailing list