Lines Matching refs:self
47 def __init__(self, future, fn, args, kwargs):
48 self.future = future
49 self.fn = fn
50 self.args = args
51 self.kwargs = kwargs
53 def run(self):
54 if not self.future.set_running_or_notify_cancel():
58 result = self.fn(*self.args, **self.kwargs)
60 self.future.set_exception(exc)
62 self = None
64 self.future.set_result(result)
123 def __init__(self, max_workers=None, thread_name_prefix='',
149 self._max_workers = max_workers
150 self._work_queue = queue.SimpleQueue()
151 self._idle_semaphore = threading.Semaphore(0)
152 self._threads = set()
153 self._broken = False
154 self._shutdown = False
155 self._shutdown_lock = threading.Lock()
156 self._thread_name_prefix = (thread_name_prefix or
157 ("ThreadPoolExecutor-%d" % self._counter()))
158 self._initializer = initializer
159 self._initargs = initargs
161 def submit(self, fn, /, *args, **kwargs):
162 with self._shutdown_lock, _global_shutdown_lock:
163 if self._broken:
164 raise BrokenThreadPool(self._broken)
166 if self._shutdown:
175 self._work_queue.put(w)
176 self._adjust_thread_count()
180 def _adjust_thread_count(self):
182 if self._idle_semaphore.acquire(timeout=0):
187 def weakref_cb(_, q=self._work_queue):
190 num_threads = len(self._threads)
191 if num_threads < self._max_workers:
192 thread_name = '%s_%d' % (self._thread_name_prefix or self,
195 args=(weakref.ref(self, weakref_cb),
196 self._work_queue,
197 self._initializer,
198 self._initargs))
200 self._threads.add(t)
201 _threads_queues[t] = self._work_queue
203 def _initializer_failed(self):
204 with self._shutdown_lock:
205 self._broken = ('A thread initializer failed, the thread pool '
210 work_item = self._work_queue.get_nowait()
214 work_item.future.set_exception(BrokenThreadPool(self._broken))
216 def shutdown(self, wait=True, *, cancel_futures=False):
217 with self._shutdown_lock:
218 self._shutdown = True
224 work_item = self._work_queue.get_nowait()
232 self._work_queue.put(None)
234 for t in self._threads: