Revision 189d2714 lib/workerpool.py
b/lib/workerpool.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2008 Google Inc. |
|
4 |
# Copyright (C) 2008, 2009, 2010 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
189 | 189 |
while self._quiescing: |
190 | 190 |
self._pool_to_pool.wait() |
191 | 191 |
|
192 |
def _AddTaskUnlocked(self, args): |
|
193 |
assert isinstance(args, (tuple, list)), "Arguments must be a sequence" |
|
194 |
|
|
195 |
self._tasks.append(args) |
|
196 |
|
|
197 |
# Notify a waiting worker |
|
198 |
self._pool_to_worker.notify() |
|
199 |
|
|
192 | 200 |
def AddTask(self, *args): |
193 | 201 |
"""Adds a task to the queue. |
194 | 202 |
|
... | ... | |
198 | 206 |
self._lock.acquire() |
199 | 207 |
try: |
200 | 208 |
self._WaitWhileQuiescingUnlocked() |
201 |
|
|
202 |
self._tasks.append(args) |
|
203 |
|
|
204 |
# Wake one idling worker up |
|
205 |
self._pool_to_worker.notify() |
|
209 |
self._AddTaskUnlocked(args) |
|
206 | 210 |
finally: |
207 | 211 |
self._lock.release() |
208 | 212 |
|
... | ... | |
220 | 224 |
try: |
221 | 225 |
self._WaitWhileQuiescingUnlocked() |
222 | 226 |
|
223 |
self._tasks.extend(tasks) |
|
224 |
|
|
225 |
for _ in tasks: |
|
226 |
self._pool_to_worker.notify() |
|
227 |
for args in tasks: |
|
228 |
self._AddTaskUnlocked(args) |
|
227 | 229 |
finally: |
228 | 230 |
self._lock.release() |
229 | 231 |
|
Also available in: Unified diff