root / lib / workerpool.py @ 34b6ab97
History | View | Annotate | Download (9 kB)
1 | 76094e37 | Michael Hanselmann | #
|
---|---|---|---|
2 | 76094e37 | Michael Hanselmann | #
|
3 | 76094e37 | Michael Hanselmann | |
4 | 76094e37 | Michael Hanselmann | # Copyright (C) 2008 Google Inc.
|
5 | 76094e37 | Michael Hanselmann | #
|
6 | 76094e37 | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | 76094e37 | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | 76094e37 | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | 76094e37 | Michael Hanselmann | # (at your option) any later version.
|
10 | 76094e37 | Michael Hanselmann | #
|
11 | 76094e37 | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | 76094e37 | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 76094e37 | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 76094e37 | Michael Hanselmann | # General Public License for more details.
|
15 | 76094e37 | Michael Hanselmann | #
|
16 | 76094e37 | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | 76094e37 | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | 76094e37 | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 76094e37 | Michael Hanselmann | # 02110-1301, USA.
|
20 | 76094e37 | Michael Hanselmann | |
21 | 76094e37 | Michael Hanselmann | |
22 | 76094e37 | Michael Hanselmann | """Base classes for worker pools.
|
23 | 76094e37 | Michael Hanselmann |
|
24 | 76094e37 | Michael Hanselmann | """
|
25 | 76094e37 | Michael Hanselmann | |
26 | 76094e37 | Michael Hanselmann | import collections |
27 | 76094e37 | Michael Hanselmann | import logging |
28 | 76094e37 | Michael Hanselmann | import threading |
29 | 76094e37 | Michael Hanselmann | |
30 | 76094e37 | Michael Hanselmann | |
31 | 76094e37 | Michael Hanselmann | class BaseWorker(threading.Thread, object): |
32 | 76094e37 | Michael Hanselmann | """Base worker class for worker pools.
|
33 | 76094e37 | Michael Hanselmann |
|
34 | 76094e37 | Michael Hanselmann | Users of a worker pool must override RunTask in a subclass.
|
35 | 76094e37 | Michael Hanselmann |
|
36 | 76094e37 | Michael Hanselmann | """
|
37 | 76094e37 | Michael Hanselmann | def __init__(self, pool, worker_id): |
38 | 76094e37 | Michael Hanselmann | """Constructor for BaseWorker thread.
|
39 | 76094e37 | Michael Hanselmann |
|
40 | 76094e37 | Michael Hanselmann | Args:
|
41 | 76094e37 | Michael Hanselmann | - pool: Parent worker pool
|
42 | 76094e37 | Michael Hanselmann | - worker_id: Identifier for this worker
|
43 | 76094e37 | Michael Hanselmann |
|
44 | 76094e37 | Michael Hanselmann | """
|
45 | 76094e37 | Michael Hanselmann | super(BaseWorker, self).__init__() |
46 | 76094e37 | Michael Hanselmann | self.pool = pool
|
47 | 76094e37 | Michael Hanselmann | self.worker_id = worker_id
|
48 | 76094e37 | Michael Hanselmann | self._current_task = None |
49 | 76094e37 | Michael Hanselmann | |
50 | 76094e37 | Michael Hanselmann | def ShouldTerminate(self): |
51 | 76094e37 | Michael Hanselmann | """Returns whether a worker should terminate.
|
52 | 76094e37 | Michael Hanselmann |
|
53 | 76094e37 | Michael Hanselmann | """
|
54 | 76094e37 | Michael Hanselmann | return self.pool.ShouldWorkerTerminate(self) |
55 | 76094e37 | Michael Hanselmann | |
56 | b3558df1 | Michael Hanselmann | def _HasRunningTaskUnlocked(self): |
57 | b3558df1 | Michael Hanselmann | """Returns whether this worker is currently running a task.
|
58 | b3558df1 | Michael Hanselmann |
|
59 | b3558df1 | Michael Hanselmann | """
|
60 | b3558df1 | Michael Hanselmann | return (self._current_task is not None) |
61 | b3558df1 | Michael Hanselmann | |
62 | b3558df1 | Michael Hanselmann | def HasRunningTask(self): |
63 | b3558df1 | Michael Hanselmann | """Returns whether this worker is currently running a task.
|
64 | b3558df1 | Michael Hanselmann |
|
65 | b3558df1 | Michael Hanselmann | """
|
66 | b3558df1 | Michael Hanselmann | self.pool._lock.acquire()
|
67 | b3558df1 | Michael Hanselmann | try:
|
68 | b3558df1 | Michael Hanselmann | return self._HasRunningTaskUnlocked() |
69 | b3558df1 | Michael Hanselmann | finally:
|
70 | b3558df1 | Michael Hanselmann | self.pool._lock.release()
|
71 | b3558df1 | Michael Hanselmann | |
72 | 76094e37 | Michael Hanselmann | def run(self): |
73 | 76094e37 | Michael Hanselmann | """Main thread function.
|
74 | 76094e37 | Michael Hanselmann |
|
75 | 76094e37 | Michael Hanselmann | Waits for new tasks to show up in the queue.
|
76 | 76094e37 | Michael Hanselmann |
|
77 | 76094e37 | Michael Hanselmann | """
|
78 | 76094e37 | Michael Hanselmann | pool = self.pool
|
79 | 76094e37 | Michael Hanselmann | |
80 | b3558df1 | Michael Hanselmann | assert not self.HasRunningTask() |
81 | 76094e37 | Michael Hanselmann | |
82 | 76094e37 | Michael Hanselmann | while True: |
83 | 76094e37 | Michael Hanselmann | try:
|
84 | 76094e37 | Michael Hanselmann | # We wait on lock to be told either terminate or do a task.
|
85 | 76094e37 | Michael Hanselmann | pool._lock.acquire() |
86 | 76094e37 | Michael Hanselmann | try:
|
87 | 76094e37 | Michael Hanselmann | if pool._ShouldWorkerTerminateUnlocked(self): |
88 | 76094e37 | Michael Hanselmann | break
|
89 | 76094e37 | Michael Hanselmann | |
90 | 76094e37 | Michael Hanselmann | # We only wait if there's no task for us.
|
91 | 76094e37 | Michael Hanselmann | if not pool._tasks: |
92 | b3558df1 | Michael Hanselmann | logging.debug("Worker %s: waiting for tasks", self.worker_id) |
93 | b3558df1 | Michael Hanselmann | |
94 | 76094e37 | Michael Hanselmann | # wait() releases the lock and sleeps until notified
|
95 | 53b1d12b | Michael Hanselmann | pool._pool_to_worker.wait() |
96 | 76094e37 | Michael Hanselmann | |
97 | b3558df1 | Michael Hanselmann | logging.debug("Worker %s: notified while waiting", self.worker_id) |
98 | b3558df1 | Michael Hanselmann | |
99 | 76094e37 | Michael Hanselmann | # Were we woken up in order to terminate?
|
100 | 76094e37 | Michael Hanselmann | if pool._ShouldWorkerTerminateUnlocked(self): |
101 | 76094e37 | Michael Hanselmann | break
|
102 | 76094e37 | Michael Hanselmann | |
103 | 76094e37 | Michael Hanselmann | if not pool._tasks: |
104 | 76094e37 | Michael Hanselmann | # Spurious notification, ignore
|
105 | 76094e37 | Michael Hanselmann | continue
|
106 | 76094e37 | Michael Hanselmann | |
107 | 76094e37 | Michael Hanselmann | # Get task from queue and tell pool about it
|
108 | 76094e37 | Michael Hanselmann | try:
|
109 | 76094e37 | Michael Hanselmann | self._current_task = pool._tasks.popleft()
|
110 | 76094e37 | Michael Hanselmann | finally:
|
111 | 53b1d12b | Michael Hanselmann | pool._worker_to_pool.notifyAll() |
112 | 76094e37 | Michael Hanselmann | finally:
|
113 | 76094e37 | Michael Hanselmann | pool._lock.release() |
114 | 76094e37 | Michael Hanselmann | |
115 | 76094e37 | Michael Hanselmann | # Run the actual task
|
116 | 76094e37 | Michael Hanselmann | try:
|
117 | b3558df1 | Michael Hanselmann | logging.debug("Worker %s: starting task %r",
|
118 | b3558df1 | Michael Hanselmann | self.worker_id, self._current_task) |
119 | 76094e37 | Michael Hanselmann | self.RunTask(*self._current_task) |
120 | b3558df1 | Michael Hanselmann | logging.debug("Worker %s: done with task %r",
|
121 | b3558df1 | Michael Hanselmann | self.worker_id, self._current_task) |
122 | 76094e37 | Michael Hanselmann | except:
|
123 | 76094e37 | Michael Hanselmann | logging.error("Worker %s: Caught unhandled exception",
|
124 | 76094e37 | Michael Hanselmann | self.worker_id, exc_info=True) |
125 | 76094e37 | Michael Hanselmann | finally:
|
126 | 76094e37 | Michael Hanselmann | # Notify pool
|
127 | 76094e37 | Michael Hanselmann | pool._lock.acquire() |
128 | 76094e37 | Michael Hanselmann | try:
|
129 | b3558df1 | Michael Hanselmann | if self._current_task: |
130 | b3558df1 | Michael Hanselmann | self._current_task = None |
131 | 53b1d12b | Michael Hanselmann | pool._worker_to_pool.notifyAll() |
132 | 76094e37 | Michael Hanselmann | finally:
|
133 | 76094e37 | Michael Hanselmann | pool._lock.release() |
134 | 76094e37 | Michael Hanselmann | |
135 | b3558df1 | Michael Hanselmann | logging.debug("Worker %s: terminates", self.worker_id) |
136 | b3558df1 | Michael Hanselmann | |
137 | 76094e37 | Michael Hanselmann | def RunTask(self, *args): |
138 | 76094e37 | Michael Hanselmann | """Function called to start a task.
|
139 | 76094e37 | Michael Hanselmann |
|
140 | 76094e37 | Michael Hanselmann | """
|
141 | 76094e37 | Michael Hanselmann | raise NotImplementedError() |
142 | 76094e37 | Michael Hanselmann | |
143 | 76094e37 | Michael Hanselmann | |
144 | 76094e37 | Michael Hanselmann | class WorkerPool(object): |
145 | 76094e37 | Michael Hanselmann | """Worker pool with a queue.
|
146 | 76094e37 | Michael Hanselmann |
|
147 | 76094e37 | Michael Hanselmann | This class is thread-safe.
|
148 | 76094e37 | Michael Hanselmann |
|
149 | 76094e37 | Michael Hanselmann | Tasks are guaranteed to be started in the order in which they're added to the
|
150 | 76094e37 | Michael Hanselmann | pool. Due to the nature of threading, they're not guaranteed to finish in the
|
151 | 76094e37 | Michael Hanselmann | same order.
|
152 | 76094e37 | Michael Hanselmann |
|
153 | 76094e37 | Michael Hanselmann | """
|
154 | 76094e37 | Michael Hanselmann | def __init__(self, num_workers, worker_class): |
155 | 76094e37 | Michael Hanselmann | """Constructor for worker pool.
|
156 | 76094e37 | Michael Hanselmann |
|
157 | 76094e37 | Michael Hanselmann | Args:
|
158 | 76094e37 | Michael Hanselmann | - num_workers: Number of workers to be started (dynamic resizing is not
|
159 | 76094e37 | Michael Hanselmann | yet implemented)
|
160 | 76094e37 | Michael Hanselmann | - worker_class: Class to be instantiated for workers; should derive from
|
161 | 76094e37 | Michael Hanselmann | BaseWorker
|
162 | 76094e37 | Michael Hanselmann |
|
163 | 76094e37 | Michael Hanselmann | """
|
164 | 76094e37 | Michael Hanselmann | # Some of these variables are accessed by BaseWorker
|
165 | 53b1d12b | Michael Hanselmann | self._lock = threading.Lock()
|
166 | 53b1d12b | Michael Hanselmann | self._pool_to_pool = threading.Condition(self._lock) |
167 | 53b1d12b | Michael Hanselmann | self._pool_to_worker = threading.Condition(self._lock) |
168 | 53b1d12b | Michael Hanselmann | self._worker_to_pool = threading.Condition(self._lock) |
169 | 76094e37 | Michael Hanselmann | self._worker_class = worker_class
|
170 | 76094e37 | Michael Hanselmann | self._last_worker_id = 0 |
171 | 76094e37 | Michael Hanselmann | self._workers = []
|
172 | 76094e37 | Michael Hanselmann | self._quiescing = False |
173 | 76094e37 | Michael Hanselmann | |
174 | 76094e37 | Michael Hanselmann | # Terminating workers
|
175 | 76094e37 | Michael Hanselmann | self._termworkers = []
|
176 | 76094e37 | Michael Hanselmann | |
177 | 76094e37 | Michael Hanselmann | # Queued tasks
|
178 | 76094e37 | Michael Hanselmann | self._tasks = collections.deque()
|
179 | 76094e37 | Michael Hanselmann | |
180 | 76094e37 | Michael Hanselmann | # Start workers
|
181 | 76094e37 | Michael Hanselmann | self.Resize(num_workers)
|
182 | 76094e37 | Michael Hanselmann | |
183 | 76094e37 | Michael Hanselmann | # TODO: Implement dynamic resizing?
|
184 | 76094e37 | Michael Hanselmann | |
185 | 76094e37 | Michael Hanselmann | def AddTask(self, *args): |
186 | 76094e37 | Michael Hanselmann | """Adds a task to the queue.
|
187 | 76094e37 | Michael Hanselmann |
|
188 | 76094e37 | Michael Hanselmann | Args:
|
189 | 76094e37 | Michael Hanselmann | - *args: Arguments passed to BaseWorker.RunTask
|
190 | 76094e37 | Michael Hanselmann |
|
191 | 76094e37 | Michael Hanselmann | """
|
192 | 76094e37 | Michael Hanselmann | self._lock.acquire()
|
193 | 76094e37 | Michael Hanselmann | try:
|
194 | 76094e37 | Michael Hanselmann | # Don't add new tasks while we're quiescing
|
195 | 76094e37 | Michael Hanselmann | while self._quiescing: |
196 | 53b1d12b | Michael Hanselmann | self._pool_to_pool.wait()
|
197 | 76094e37 | Michael Hanselmann | |
198 | 76094e37 | Michael Hanselmann | # Add task to internal queue
|
199 | 76094e37 | Michael Hanselmann | self._tasks.append(args)
|
200 | 53b1d12b | Michael Hanselmann | |
201 | 53b1d12b | Michael Hanselmann | # Wake one idling worker up
|
202 | 53b1d12b | Michael Hanselmann | self._pool_to_worker.notify()
|
203 | 76094e37 | Michael Hanselmann | finally:
|
204 | 76094e37 | Michael Hanselmann | self._lock.release()
|
205 | 76094e37 | Michael Hanselmann | |
206 | 76094e37 | Michael Hanselmann | def _ShouldWorkerTerminateUnlocked(self, worker): |
207 | 76094e37 | Michael Hanselmann | """Returns whether a worker should terminate.
|
208 | 76094e37 | Michael Hanselmann |
|
209 | 76094e37 | Michael Hanselmann | """
|
210 | 76094e37 | Michael Hanselmann | return (worker in self._termworkers) |
211 | 76094e37 | Michael Hanselmann | |
212 | 76094e37 | Michael Hanselmann | def ShouldWorkerTerminate(self, worker): |
213 | 76094e37 | Michael Hanselmann | """Returns whether a worker should terminate.
|
214 | 76094e37 | Michael Hanselmann |
|
215 | 76094e37 | Michael Hanselmann | """
|
216 | 76094e37 | Michael Hanselmann | self._lock.acquire()
|
217 | 76094e37 | Michael Hanselmann | try:
|
218 | 76094e37 | Michael Hanselmann | return self._ShouldWorkerTerminateUnlocked(self) |
219 | 76094e37 | Michael Hanselmann | finally:
|
220 | 76094e37 | Michael Hanselmann | self._lock.release()
|
221 | 76094e37 | Michael Hanselmann | |
222 | 76094e37 | Michael Hanselmann | def _HasRunningTasksUnlocked(self): |
223 | 76094e37 | Michael Hanselmann | """Checks whether there's a task running in a worker.
|
224 | 76094e37 | Michael Hanselmann |
|
225 | 76094e37 | Michael Hanselmann | """
|
226 | 76094e37 | Michael Hanselmann | for worker in self._workers + self._termworkers: |
227 | b3558df1 | Michael Hanselmann | if worker._HasRunningTaskUnlocked():
|
228 | 76094e37 | Michael Hanselmann | return True |
229 | 76094e37 | Michael Hanselmann | return False |
230 | 76094e37 | Michael Hanselmann | |
231 | 76094e37 | Michael Hanselmann | def Quiesce(self): |
232 | 76094e37 | Michael Hanselmann | """Waits until the task queue is empty.
|
233 | 76094e37 | Michael Hanselmann |
|
234 | 76094e37 | Michael Hanselmann | """
|
235 | 76094e37 | Michael Hanselmann | self._lock.acquire()
|
236 | 76094e37 | Michael Hanselmann | try:
|
237 | 76094e37 | Michael Hanselmann | self._quiescing = True |
238 | 76094e37 | Michael Hanselmann | |
239 | 76094e37 | Michael Hanselmann | # Wait while there are tasks pending or running
|
240 | 76094e37 | Michael Hanselmann | while self._tasks or self._HasRunningTasksUnlocked(): |
241 | 53b1d12b | Michael Hanselmann | self._worker_to_pool.wait()
|
242 | 76094e37 | Michael Hanselmann | |
243 | 76094e37 | Michael Hanselmann | finally:
|
244 | 76094e37 | Michael Hanselmann | self._quiescing = False |
245 | 76094e37 | Michael Hanselmann | |
246 | 76094e37 | Michael Hanselmann | # Make sure AddTasks continues in case it was waiting
|
247 | 53b1d12b | Michael Hanselmann | self._pool_to_pool.notifyAll()
|
248 | 76094e37 | Michael Hanselmann | |
249 | 76094e37 | Michael Hanselmann | self._lock.release()
|
250 | 76094e37 | Michael Hanselmann | |
251 | 76094e37 | Michael Hanselmann | def _NewWorkerIdUnlocked(self): |
252 | 76094e37 | Michael Hanselmann | self._last_worker_id += 1 |
253 | 76094e37 | Michael Hanselmann | return self._last_worker_id |
254 | 76094e37 | Michael Hanselmann | |
255 | 76094e37 | Michael Hanselmann | def _ResizeUnlocked(self, num_workers): |
256 | 76094e37 | Michael Hanselmann | """Changes the number of workers.
|
257 | 76094e37 | Michael Hanselmann |
|
258 | 76094e37 | Michael Hanselmann | """
|
259 | 76094e37 | Michael Hanselmann | assert num_workers >= 0, "num_workers must be >= 0" |
260 | 76094e37 | Michael Hanselmann | |
261 | 76094e37 | Michael Hanselmann | logging.debug("Resizing to %s workers", num_workers)
|
262 | 76094e37 | Michael Hanselmann | |
263 | 76094e37 | Michael Hanselmann | current_count = len(self._workers) |
264 | 76094e37 | Michael Hanselmann | |
265 | 76094e37 | Michael Hanselmann | if current_count == num_workers:
|
266 | 76094e37 | Michael Hanselmann | # Nothing to do
|
267 | 76094e37 | Michael Hanselmann | pass
|
268 | 76094e37 | Michael Hanselmann | |
269 | 76094e37 | Michael Hanselmann | elif current_count > num_workers:
|
270 | 76094e37 | Michael Hanselmann | if num_workers == 0: |
271 | 76094e37 | Michael Hanselmann | # Create copy of list to iterate over while lock isn't held.
|
272 | 76094e37 | Michael Hanselmann | termworkers = self._workers[:]
|
273 | 76094e37 | Michael Hanselmann | del self._workers[:] |
274 | 76094e37 | Michael Hanselmann | else:
|
275 | 76094e37 | Michael Hanselmann | # TODO: Implement partial downsizing
|
276 | 76094e37 | Michael Hanselmann | raise NotImplementedError() |
277 | 76094e37 | Michael Hanselmann | #termworkers = ...
|
278 | 76094e37 | Michael Hanselmann | |
279 | 76094e37 | Michael Hanselmann | self._termworkers += termworkers
|
280 | 76094e37 | Michael Hanselmann | |
281 | 76094e37 | Michael Hanselmann | # Notify workers that something has changed
|
282 | 53b1d12b | Michael Hanselmann | self._pool_to_worker.notifyAll()
|
283 | 76094e37 | Michael Hanselmann | |
284 | 76094e37 | Michael Hanselmann | # Join all terminating workers
|
285 | 76094e37 | Michael Hanselmann | self._lock.release()
|
286 | 76094e37 | Michael Hanselmann | try:
|
287 | 76094e37 | Michael Hanselmann | for worker in termworkers: |
288 | c0a8eb9e | Michael Hanselmann | logging.debug("Waiting for thread %s", worker.getName())
|
289 | 76094e37 | Michael Hanselmann | worker.join() |
290 | 76094e37 | Michael Hanselmann | finally:
|
291 | 76094e37 | Michael Hanselmann | self._lock.acquire()
|
292 | 76094e37 | Michael Hanselmann | |
293 | 76094e37 | Michael Hanselmann | # Remove terminated threads. This could be done in a more efficient way
|
294 | 76094e37 | Michael Hanselmann | # (del self._termworkers[:]), but checking worker.isAlive() makes sure we
|
295 | 76094e37 | Michael Hanselmann | # don't leave zombie threads around.
|
296 | 76094e37 | Michael Hanselmann | for worker in termworkers: |
297 | 76094e37 | Michael Hanselmann | assert worker in self._termworkers, ("Worker not in list of" |
298 | 76094e37 | Michael Hanselmann | " terminating workers")
|
299 | 76094e37 | Michael Hanselmann | if not worker.isAlive(): |
300 | 76094e37 | Michael Hanselmann | self._termworkers.remove(worker)
|
301 | 76094e37 | Michael Hanselmann | |
302 | 76094e37 | Michael Hanselmann | assert not self._termworkers, "Zombie worker detected" |
303 | 76094e37 | Michael Hanselmann | |
304 | 76094e37 | Michael Hanselmann | elif current_count < num_workers:
|
305 | 76094e37 | Michael Hanselmann | # Create (num_workers - current_count) new workers
|
306 | 76094e37 | Michael Hanselmann | for i in xrange(num_workers - current_count): |
307 | 76094e37 | Michael Hanselmann | worker = self._worker_class(self, self._NewWorkerIdUnlocked()) |
308 | 76094e37 | Michael Hanselmann | self._workers.append(worker)
|
309 | 76094e37 | Michael Hanselmann | worker.start() |
310 | 76094e37 | Michael Hanselmann | |
311 | 76094e37 | Michael Hanselmann | def Resize(self, num_workers): |
312 | 76094e37 | Michael Hanselmann | """Changes the number of workers in the pool.
|
313 | 76094e37 | Michael Hanselmann |
|
314 | 76094e37 | Michael Hanselmann | Args:
|
315 | 76094e37 | Michael Hanselmann | - num_workers: New number of workers
|
316 | 76094e37 | Michael Hanselmann |
|
317 | 76094e37 | Michael Hanselmann | """
|
318 | 76094e37 | Michael Hanselmann | self._lock.acquire()
|
319 | 76094e37 | Michael Hanselmann | try:
|
320 | 76094e37 | Michael Hanselmann | return self._ResizeUnlocked(num_workers) |
321 | 76094e37 | Michael Hanselmann | finally:
|
322 | 76094e37 | Michael Hanselmann | self._lock.release()
|
323 | 76094e37 | Michael Hanselmann | |
324 | 76094e37 | Michael Hanselmann | def TerminateWorkers(self): |
325 | 76094e37 | Michael Hanselmann | """Terminate all worker threads.
|
326 | 76094e37 | Michael Hanselmann |
|
327 | 76094e37 | Michael Hanselmann | Unstarted tasks will be ignored.
|
328 | 76094e37 | Michael Hanselmann |
|
329 | 76094e37 | Michael Hanselmann | """
|
330 | 76094e37 | Michael Hanselmann | logging.debug("Terminating all workers")
|
331 | 76094e37 | Michael Hanselmann | |
332 | 76094e37 | Michael Hanselmann | self._lock.acquire()
|
333 | 76094e37 | Michael Hanselmann | try:
|
334 | 76094e37 | Michael Hanselmann | self._ResizeUnlocked(0) |
335 | 76094e37 | Michael Hanselmann | |
336 | 76094e37 | Michael Hanselmann | if self._tasks: |
337 | 76094e37 | Michael Hanselmann | logging.debug("There are %s tasks left", len(self._tasks)) |
338 | 76094e37 | Michael Hanselmann | finally:
|
339 | 76094e37 | Michael Hanselmann | self._lock.release()
|
340 | 76094e37 | Michael Hanselmann | |
341 | 76094e37 | Michael Hanselmann | logging.debug("All workers terminated") |