[python-ldap] Processing query in spans of time with timeout and resuming
Max Gautier
mg at max.gautier.name
Sat Jul 2 07:01:35 EDT 2022
Hi everyone,
I'm trying to use python-ldap to write a vim completion plugin
(more specically, a completion source for vim-asyncomplete[1]), and I'm not sure if
what I want is possible.
Basically, I'd like to do launch a LDAP query, and return results either:
1. When the query is finished
2. After a soft timeout
With the possibility in the second case to re-loop and each time get the
results up to now.
I was trying to use the ldap.resiter.ResultProcessor as the docs seems
to recommend that, but I think I would need to wrap it in something else
to obtain the desired behaviour.
I thought about doing it this way:
---
class LdapSoftTimeout(ldap.ldapobject.LDAPObject, ldap.resiter.ResultProcessor):
pass
con = ldap.initialize("ldaps://myuri")
con.sasl_gssapi_bind_s()
msg_id = con.search('ou=users,dc=mycompany,dc=com', ldap.SCOPE_SUBTREE, '(cn=*Go*)', ['cn', 'mail'])
# Keep that whole context somehow, then do a function returning partial
# results each time it's called, something like :
partial_results = list()
now = time.time()
timeout = 0.1
for r in con.allresults(msgid=search):
if time.time() > now + timeout
break
list.append(some_processing(r))
return partial_results
---
However this does not seem very efficient to me.
Does someone have encountered that kind of usecase and would have a
better idea ?
I'm not a very experienced pythonista, so I might have missed something
obvious, but my search on google on this mailing list were not fruitful,
so don't hesitate to point me to the obvious solution if there is one.
Thanks a lot :)
--
Max Gautier
More information about the python-ldap
mailing list