Revision 116db7c7
b/lib/workerpool.py | ||
---|---|---|
37 | 37 |
def __init__(self, pool, worker_id): |
38 | 38 |
"""Constructor for BaseWorker thread. |
39 | 39 |
|
40 |
Args: |
|
41 |
- pool: Parent worker pool |
|
42 |
- worker_id: Identifier for this worker |
|
40 |
@param pool: the parent worker pool |
|
41 |
@param worker_id: identifier for this worker |
|
43 | 42 |
|
44 | 43 |
""" |
45 | 44 |
super(BaseWorker, self).__init__() |
... | ... | |
137 | 136 |
def RunTask(self, *args): |
138 | 137 |
"""Function called to start a task. |
139 | 138 |
|
139 |
This needs to be implemented by child classes. |
|
140 |
|
|
140 | 141 |
""" |
141 | 142 |
raise NotImplementedError() |
142 | 143 |
|
... | ... | |
146 | 147 |
|
147 | 148 |
This class is thread-safe. |
148 | 149 |
|
149 |
Tasks are guaranteed to be started in the order in which they're added to the
|
|
150 |
pool. Due to the nature of threading, they're not guaranteed to finish in the
|
|
151 |
same order. |
|
150 |
Tasks are guaranteed to be started in the order in which they're |
|
151 |
added to the pool. Due to the nature of threading, they're not
|
|
152 |
guaranteed to finish in the same order.
|
|
152 | 153 |
|
153 | 154 |
""" |
154 | 155 |
def __init__(self, num_workers, worker_class): |
155 | 156 |
"""Constructor for worker pool. |
156 | 157 |
|
157 |
Args: |
|
158 |
- num_workers: Number of workers to be started (dynamic resizing is not |
|
159 |
yet implemented) |
|
160 |
- worker_class: Class to be instantiated for workers; should derive from |
|
161 |
BaseWorker |
|
158 |
@param num_workers: number of workers to be started |
|
159 |
(dynamic resizing is not yet implemented) |
|
160 |
@param worker_class: the class to be instantiated for workers; |
|
161 |
should derive from L{BaseWorker} |
|
162 | 162 |
|
163 | 163 |
""" |
164 | 164 |
# Some of these variables are accessed by BaseWorker |
... | ... | |
185 | 185 |
def AddTask(self, *args): |
186 | 186 |
"""Adds a task to the queue. |
187 | 187 |
|
188 |
Args: |
|
189 |
- *args: Arguments passed to BaseWorker.RunTask |
|
188 |
@param args: arguments passed to L{BaseWorker.RunTask} |
|
190 | 189 |
|
191 | 190 |
""" |
192 | 191 |
self._lock.acquire() |
... | ... | |
249 | 248 |
self._lock.release() |
250 | 249 |
|
251 | 250 |
def _NewWorkerIdUnlocked(self): |
251 |
"""Return an identifier for a new worker. |
|
252 |
|
|
253 |
""" |
|
252 | 254 |
self._last_worker_id += 1 |
253 | 255 |
return self._last_worker_id |
254 | 256 |
|
... | ... | |
311 | 313 |
def Resize(self, num_workers): |
312 | 314 |
"""Changes the number of workers in the pool. |
313 | 315 |
|
314 |
Args: |
|
315 |
- num_workers: New number of workers |
|
316 |
@param num_workers: the new number of workers |
|
316 | 317 |
|
317 | 318 |
""" |
318 | 319 |
self._lock.acquire() |
Also available in: Unified diff