MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / PoolLocker

Class PoolLocker

test/test_load_balancer.py:162–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160
161
162class PoolLocker(ExceptionCatchingTask):
163 def __init__(self, pool):
164 super().__init__(target=self.lock_pool)
165 self.pool = pool
166 self.daemon = True
167 self.locked = create_event()
168 self.unlock = create_event()
169
170 def lock_pool(self):
171 with self.pool.lock:
172 self.locked.set()
173 # Wait for the unlock flag.
174 unlock_pool = self.wait(self.unlock, 10)
175 if not unlock_pool:
176 raise Exception("timed out waiting for unlock signal: deadlock?")
177
178 def wait(self, event: Event, timeout: int):
179 if _IS_SYNC:
180 return event.wait(timeout) # type: ignore[call-arg]
181 else:
182 try:
183 asyncio.wait_for(event.wait(), timeout=timeout)
184 except asyncio.TimeoutError:
185 return False
186 return True
187
188
189if __name__ == "__main__":

Callers 2

_test_no_gc_deadlockMethod · 0.70
test_session_gcMethod · 0.70

Calls

no outgoing calls

Tested by 2

_test_no_gc_deadlockMethod · 0.56
test_session_gcMethod · 0.56