in asfpy/aioldap.py [0:0]
def __init__(self, client, executor):
# NOTE: must be instantiated within one of the EXECUTOR threads.
# Shared Executor holding one or more threads.
self.executor = executor
# bonsai.LDAPConnection ties itself to a loop. Thus, whatever
# loop is used to create the connection must also be used to
# perform its operations. We will construct that loop here,
# and use it for all bonsai actions. It does not have any
# thread affinity, until it is running. Thus, we can use this
# loop within any thread of the Executor.
self.loop = asyncio.new_event_loop()
# Hack around GnuTLS bug with async.
# See: https://github.com/noirello/bonsai/issues/25
# and: https://github.com/noirello/bonsai/issues/69
#
# In THIS executor thread, we'll perform the synchronous
# connection, so that the main thread's event loop will
# not be blocked.
async def do_connect():
### for testing: pretend this connection blocks
#import time; time.sleep(5)
# Tell bonsai to connect synchronously.
bonsai.set_connect_async(False)
try:
# Ties to self.loop (the running loop now).
return await client.connect(is_async=True)
finally:
# Make sure this always gets reset.
bonsai.set_connect_async(True)
# The underlying LDAP connection, tied to our loop.
self.conn = self.loop.run_until_complete(do_connect())