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