MCPcopy Index your code
hub / github.com/python/cpython / imap

Method imap

Lib/multiprocessing/pool.py:396–423  ·  view source on GitHub ↗

Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.

(self, func, iterable, chunksize=1)

Source from the content-addressed store, hash-verified

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 ''&#x27;

Callers 4

test_empty_iterableMethod · 0.95
testFunction · 0.80
test_imapMethod · 0.80

Calls 6

_check_runningMethod · 0.95
IMapIteratorClass · 0.85
_get_tasksMethod · 0.80
putMethod · 0.45
formatMethod · 0.45

Tested by 3

test_empty_iterableMethod · 0.76
test_imapMethod · 0.64