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

Class MapResult

Lib/multiprocessing/pool.py:794–831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

792#
793
794class MapResult(ApplyResult):
795
796 def __init__(self, pool, chunksize, length, callback, error_callback):
797 ApplyResult.__init__(self, pool, callback,
798 error_callback=error_callback)
799 self._success = True
800 self._value = [None] * length
801 self._chunksize = chunksize
802 if chunksize <= 0:
803 self._number_left = 0
804 self._event.set()
805 del self._cache[self._job]
806 else:
807 self._number_left = length//chunksize + bool(length % chunksize)
808
809 def _set(self, i, success_result):
810 self._number_left -= 1
811 success, result = success_result
812 if success and self._success:
813 self._value[i*self._chunksize:(i+1)*self._chunksize] = result
814 if self._number_left == 0:
815 if self._callback:
816 self._callback(self._value)
817 del self._cache[self._job]
818 self._event.set()
819 self._pool = None
820 else:
821 if not success and self._success:
822 # only store first exception
823 self._success = False
824 self._value = result
825 if self._number_left == 0:
826 # only consider the result ready once all jobs are done
827 if self._error_callback:
828 self._error_callback(self._value)
829 del self._cache[self._job]
830 self._event.set()
831 self._pool = None
832
833#
834# Class whose instances are returned by `Pool.imap()`

Callers 1

_map_asyncMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…