MCPcopy
hub / github.com/scrapy/scrapy / parallel

Function parallel

scrapy/utils/defer.py:159–173  ·  view source on GitHub ↗

Execute a callable over the objects in the given iterable, in parallel, using no more than ``count`` concurrent calls. Taken from: https://jcalderone.livejournal.com/24285.html

(
    iterable: Iterable[_T],
    count: int,
    callable: Callable[Concatenate[_T, _P], _T2],  # noqa: A002
    *args: _P.args,
    **named: _P.kwargs,
)

Source from the content-addressed store, hash-verified

157
158
159def parallel(
160 iterable: Iterable[_T],
161 count: int,
162 callable: Callable[Concatenate[_T, _P], _T2], # noqa: A002
163 *args: _P.args,
164 **named: _P.kwargs,
165) -> Deferred[list[tuple[bool, Iterator[_T2]]]]:
166 """Execute a callable over the objects in the given iterable, in parallel,
167 using no more than ``count`` concurrent calls.
168
169 Taken from: https://jcalderone.livejournal.com/24285.html
170 """
171 coop = Cooperator()
172 work: Iterator[_T2] = (callable(elem, *args, **named) for elem in iterable)
173 return DeferredList([coop.coiterate(work) for _ in range(count)])
174
175
176class _AsyncCooperatorAdapter(Iterator[Deferred[Any]], Generic[_T]):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected