Waits until there is a server matching the specified predicate connected to this adapter, and returns the corresponding Connection. If there is more than one server connection already available, returns the oldest one.
(session, predicate, timeout=None)
| 419 | |
| 420 | |
| 421 | def wait_for_connection(session, predicate, timeout=None): |
| 422 | """Waits until there is a server matching the specified predicate connected to |
| 423 | this adapter, and returns the corresponding Connection. |
| 424 | |
| 425 | If there is more than one server connection already available, returns the oldest |
| 426 | one. |
| 427 | """ |
| 428 | |
| 429 | def wait_for_timeout(): |
| 430 | time.sleep(timeout) |
| 431 | wait_for_timeout.timed_out = True |
| 432 | with _lock: |
| 433 | _connections_changed.set() |
| 434 | |
| 435 | wait_for_timeout.timed_out = timeout == 0 |
| 436 | if timeout: |
| 437 | thread = threading.Thread( |
| 438 | target=wait_for_timeout, name="servers.wait_for_connection() timeout" |
| 439 | ) |
| 440 | thread.daemon = True |
| 441 | thread.start() |
| 442 | |
| 443 | if timeout != 0: |
| 444 | log.info("{0} waiting for connection from debug server...", session) |
| 445 | while True: |
| 446 | with _lock: |
| 447 | _connections_changed.clear() |
| 448 | conns = (conn for conn in _connections if predicate(conn)) |
| 449 | conn = next(conns, None) |
| 450 | if conn is not None or wait_for_timeout.timed_out: |
| 451 | return conn |
| 452 | _connections_changed.wait() |
| 453 | |
| 454 | |
| 455 | def wait_until_disconnected(): |
no test coverage detected
searching dependent graphs…