MCPcopy Index your code
hub / github.com/python/cpython / _worker

Function _worker

Lib/concurrent/futures/thread.py:97–141  ·  view source on GitHub ↗
(executor_reference, ctx, work_queue)

Source from the content-addressed store, hash-verified

95
96
97def _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
144class BrokenThreadPool(_base.BrokenExecutor):

Callers

nothing calls this directly

Calls 9

_initializer_failedMethod · 0.80
initializeMethod · 0.45
criticalMethod · 0.45
get_nowaitMethod · 0.45
releaseMethod · 0.45
getMethod · 0.45
runMethod · 0.45
putMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…