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

Christopher Armstrong radix at twistedmatrix.com
Tue Apr 22 19:35:38 EDT 2003


On 2003.04.22 19:19, Allan Streib wrote:
> 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.
> 

Eek, polling is terrible. You should check out Tv's Ldaptor for Twisted:
http://twistedmatrix.com/users/tv/ldaptor/
It's a natively-Twisted LDAP client library.

Also (it's moot if you'll use ldaptor, which I recommend, but..), returning the
message ID as the result of the Deferred, and requiring the caller to poll,
is a bad idea. You would do the polling yourself (every iteration of the
mainloop, with a reactor.callLater(0, pollIt) or somesuch), and once the
result is available, trigger the Deferred with it.

-- 
 Twisted | Christopher Armstrong: International Man of Twistery
  Radix  |          Release Manager,  Twisted Project
---------+     http://twistedmatrix.com/users/radix.twistd/




More information about the Twisted-Python mailing list