MCPcopy Index your code
hub / github.com/RustPython/RustPython / _worker

Function _worker

Lib/concurrent/futures/thread.py:70–113  ·  view source on GitHub ↗
(executor_reference, work_queue, initializer, initargs)

Source from the content-addressed store, hash-verified

68
69
70def _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
116class BrokenThreadPool(_base.BrokenExecutor):

Callers

nothing calls this directly

Calls 8

initializerFunction · 0.85
_initializer_failedMethod · 0.80
criticalMethod · 0.45
get_nowaitMethod · 0.45
releaseMethod · 0.45
getMethod · 0.45
runMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected