One result call per record

Michael Ströder michael at stroeder.com
Wed Apr 23 15:35:40 CEST 2008


Ron Teitelbaum wrote:
> While polling it appears that we have to call result for every record that
> is waiting to be read.  Since we added a 250 millisecond delay between calls
> larger queries are taking a really long time.

Why do you wait such a long time in an extra time.sleep() call?

>        result = self.connection.result(id, True, 0)
>        time.sleep(0.25)

Hmm, I don't know very much of the inner workings of OpenLDAP's function 
ldap_result(). The behaviour also may depend on the version of OpenLDAP.

But how about fiddling around a little bit with the timeout argument for 
result()? You're blocking your while-loop with time.sleep() anyway. And 
the C wrapper module releases Python's GIL.

Something like

   [..within while loop..]
   try:
     result = l.result(msgid,True,0.25)
   except ldap.TIMEOUT:
     continue
   else:
     # Process result
   [..within while loop..]

I played around a little bit with the script attached on a local server 
with more than 1000 entries.

BTW: If you're after correctly dispatching results to several 
outstanding search requests you should probably use method result2() 
which also returns the message ID of the originating request:

http://python-ldap.sourceforge.net/doc/html/ldap.html#ldap.LDAPObject.result2

Use result3() if LDAPv3 extended controls are to be used to also receive 
controls sent by the server.

Ciao, Michael.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: async_result.py
Type: application/x-python
Size: 1143 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20080423/eca970f7/attachment.bin>


More information about the python-ldap mailing list