221 taskQueue = multiprocessing.Queue() |
221 taskQueue = multiprocessing.Queue() |
222 doneQueue = multiprocessing.Queue() |
222 doneQueue = multiprocessing.Queue() |
223 |
223 |
224 # Submit tasks (initially two time number of processes |
224 # Submit tasks (initially two time number of processes |
225 initialTasks = 2 * NumberOfProcesses |
225 initialTasks = 2 * NumberOfProcesses |
226 for task in argumentsList[:initialTasks]: |
226 for _ in range(initialTasks): |
227 taskQueue.put(task) |
227 taskQueue.put(argumentsList.pop(0)) |
228 |
228 |
229 # Start worker processes |
229 # Start worker processes |
230 workers = [ |
230 workers = [ |
231 multiprocessing.Process( |
231 multiprocessing.Process( |
232 target=workerTask, args=(taskQueue, doneQueue) |
232 target=workerTask, args=(taskQueue, doneQueue) |
256 if wasCancelled or cancelled(): |
256 if wasCancelled or cancelled(): |
257 # just exit the loop ignoring the results of queued tasks |
257 # just exit the loop ignoring the results of queued tasks |
258 break |
258 break |
259 |
259 |
260 if i < endIndex: |
260 if i < endIndex: |
261 taskQueue.put(argumentsList[i + initialTasks]) |
261 taskQueue.put(argumentsList.pop(0)) |
262 |
262 |
263 # Tell child processes to stop |
263 # Tell child processes to stop |
264 for _ in range(NumberOfProcesses): |
264 for _ in range(NumberOfProcesses): |
265 taskQueue.put('STOP') |
265 taskQueue.put('STOP') |
266 |
266 |