| 835 | # |
| 836 | |
| 837 | class IMapIterator(object): |
| 838 | |
| 839 | def __init__(self, pool): |
| 840 | self._pool = pool |
| 841 | self._cond = threading.Condition(threading.Lock()) |
| 842 | self._job = next(job_counter) |
| 843 | self._cache = pool._cache |
| 844 | self._items = collections.deque() |
| 845 | self._index = 0 |
| 846 | self._length = None |
| 847 | self._unsorted = {} |
| 848 | self._cache[self._job] = self |
| 849 | |
| 850 | def __iter__(self): |
| 851 | return self |
| 852 | |
| 853 | def next(self, timeout=None): |
| 854 | with self._cond: |
| 855 | try: |
| 856 | item = self._items.popleft() |
| 857 | except IndexError: |
| 858 | if self._index == self._length: |
| 859 | self._pool = None |
| 860 | raise StopIteration from None |
| 861 | self._cond.wait(timeout) |
| 862 | try: |
| 863 | item = self._items.popleft() |
| 864 | except IndexError: |
| 865 | if self._index == self._length: |
| 866 | self._pool = None |
| 867 | raise StopIteration from None |
| 868 | raise TimeoutError from None |
| 869 | |
| 870 | success, value = item |
| 871 | if success: |
| 872 | return value |
| 873 | raise value |
| 874 | |
| 875 | __next__ = next # XXX |
| 876 | |
| 877 | def _set(self, i, obj): |
| 878 | with self._cond: |
| 879 | if self._index == i: |
| 880 | self._items.append(obj) |
| 881 | self._index += 1 |
| 882 | while self._index in self._unsorted: |
| 883 | obj = self._unsorted.pop(self._index) |
| 884 | self._items.append(obj) |
| 885 | self._index += 1 |
| 886 | self._cond.notify() |
| 887 | else: |
| 888 | self._unsorted[i] = obj |
| 889 | |
| 890 | if self._index == self._length: |
| 891 | del self._cache[self._job] |
| 892 | self._pool = None |
| 893 | |
| 894 | def _set_length(self, length): |
no outgoing calls
no test coverage detected
searching dependent graphs…