(executor_reference, work_queue, initializer, initargs)
| 68 | |
| 69 | |
| 70 | def _worker(executor_reference, work_queue, initializer, initargs): |
| 71 | if initializer is not None: |
| 72 | try: |
| 73 | initializer(*initargs) |
| 74 | except BaseException: |
| 75 | _base.LOGGER.critical('Exception in initializer:', exc_info=True) |
| 76 | executor = executor_reference() |
| 77 | if executor is not None: |
| 78 | executor._initializer_failed() |
| 79 | return |
| 80 | try: |
| 81 | while True: |
| 82 | try: |
| 83 | work_item = work_queue.get_nowait() |
| 84 | except queue.Empty: |
| 85 | # attempt to increment idle count if queue is empty |
| 86 | executor = executor_reference() |
| 87 | if executor is not None: |
| 88 | executor._idle_semaphore.release() |
| 89 | del executor |
| 90 | work_item = work_queue.get(block=True) |
| 91 | |
| 92 | if work_item is not None: |
| 93 | work_item.run() |
| 94 | # Delete references to object. See GH-60488 |
| 95 | del work_item |
| 96 | continue |
| 97 | |
| 98 | executor = executor_reference() |
| 99 | # Exit if: |
| 100 | # - The interpreter is shutting down OR |
| 101 | # - The executor that owns the worker has been collected OR |
| 102 | # - The executor that owns the worker has been shutdown. |
| 103 | if _shutdown or executor is None or executor._shutdown: |
| 104 | # Flag the executor as shutting down as early as possible if it |
| 105 | # is not gc-ed yet. |
| 106 | if executor is not None: |
| 107 | executor._shutdown = True |
| 108 | # Notice other workers |
| 109 | work_queue.put(None) |
| 110 | return |
| 111 | del executor |
| 112 | except BaseException: |
| 113 | _base.LOGGER.critical('Exception in worker', exc_info=True) |
| 114 | |
| 115 | |
| 116 | class BrokenThreadPool(_base.BrokenExecutor): |
nothing calls this directly
no test coverage detected