Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
(self, func, iterable, chunksize=1)
| 394 | yield (result_job, i+1, _helper_reraises_exception, (e,), {}) |
| 395 | |
| 396 | def imap(self, func, iterable, chunksize=1): |
| 397 | ''' |
| 398 | Equivalent of `map()` -- can be MUCH slower than `Pool.map()`. |
| 399 | ''' |
| 400 | self._check_running() |
| 401 | if chunksize == 1: |
| 402 | result = IMapIterator(self) |
| 403 | self._taskqueue.put( |
| 404 | ( |
| 405 | self._guarded_task_generation(result._job, func, iterable), |
| 406 | result._set_length |
| 407 | )) |
| 408 | return result |
| 409 | else: |
| 410 | if chunksize < 1: |
| 411 | raise ValueError( |
| 412 | "Chunksize must be 1+, not {0:n}".format( |
| 413 | chunksize)) |
| 414 | task_batches = Pool._get_tasks(func, iterable, chunksize) |
| 415 | result = IMapIterator(self) |
| 416 | self._taskqueue.put( |
| 417 | ( |
| 418 | self._guarded_task_generation(result._job, |
| 419 | mapstar, |
| 420 | task_batches), |
| 421 | result._set_length |
| 422 | )) |
| 423 | return (item for chunk in result for item in chunk) |
| 424 | |
| 425 | def imap_unordered(self, func, iterable, chunksize=1): |
| 426 | ''' |