(executor_reference, ctx, work_queue)
| 95 | |
| 96 | |
| 97 | def _worker(executor_reference, ctx, work_queue): |
| 98 | try: |
| 99 | ctx.initialize() |
| 100 | except BaseException: |
| 101 | _base.LOGGER.critical('Exception in initializer:', exc_info=True) |
| 102 | executor = executor_reference() |
| 103 | if executor is not None: |
| 104 | executor._initializer_failed() |
| 105 | return |
| 106 | try: |
| 107 | while True: |
| 108 | try: |
| 109 | work_item = work_queue.get_nowait() |
| 110 | except queue.Empty: |
| 111 | # attempt to increment idle count if queue is empty |
| 112 | executor = executor_reference() |
| 113 | if executor is not None: |
| 114 | executor._idle_semaphore.release() |
| 115 | del executor |
| 116 | work_item = work_queue.get(block=True) |
| 117 | |
| 118 | if work_item is not None: |
| 119 | work_item.run(ctx) |
| 120 | # Delete references to object. See GH-60488 |
| 121 | del work_item |
| 122 | continue |
| 123 | |
| 124 | executor = executor_reference() |
| 125 | # Exit if: |
| 126 | # - The interpreter is shutting down OR |
| 127 | # - The executor that owns the worker has been collected OR |
| 128 | # - The executor that owns the worker has been shutdown. |
| 129 | if _shutdown or executor is None or executor._shutdown: |
| 130 | # Flag the executor as shutting down as early as possible if it |
| 131 | # is not gc-ed yet. |
| 132 | if executor is not None: |
| 133 | executor._shutdown = True |
| 134 | # Notice other workers |
| 135 | work_queue.put(None) |
| 136 | return |
| 137 | del executor |
| 138 | except BaseException: |
| 139 | _base.LOGGER.critical('Exception in worker', exc_info=True) |
| 140 | finally: |
| 141 | ctx.finalize() |
| 142 | |
| 143 | |
| 144 | class BrokenThreadPool(_base.BrokenExecutor): |
nothing calls this directly
no test coverage detected
searching dependent graphs…