Creates a context manager that handles starting and stopping queue runners. Args: session: the currently running session. Yields: a context in which queues are run. Raises: NestedQueueRunnerError: if a QueueRunners context is nested within another.
(session)
| 42 | |
| 43 | @contextmanager |
| 44 | def QueueRunners(session): |
| 45 | """Creates a context manager that handles starting and stopping queue runners. |
| 46 | |
| 47 | Args: |
| 48 | session: the currently running session. |
| 49 | |
| 50 | Yields: |
| 51 | a context in which queues are run. |
| 52 | |
| 53 | Raises: |
| 54 | NestedQueueRunnerError: if a QueueRunners context is nested within another. |
| 55 | """ |
| 56 | if not _queue_runner_lock.acquire(False): |
| 57 | raise NestedQueueRunnerError('QueueRunners cannot be nested') |
| 58 | |
| 59 | coord = coordinator.Coordinator() |
| 60 | threads = [] |
| 61 | for qr in ops.get_collection(ops.GraphKeys.QUEUE_RUNNERS): |
| 62 | threads.extend( |
| 63 | qr.create_threads( |
| 64 | session, coord=coord, daemon=True, start=True)) |
| 65 | try: |
| 66 | yield |
| 67 | finally: |
| 68 | coord.request_stop() |
| 69 | try: |
| 70 | coord.join(threads, stop_grace_period_secs=120) |
| 71 | except RuntimeError: |
| 72 | session.close() |
| 73 | |
| 74 | _queue_runner_lock.release() |
nothing calls this directly
no test coverage detected