MCPcopy
hub / github.com/scrapy/scrapy / run_in_thread

Function run_in_thread

scrapy/utils/asyncio.py:296–313  ·  view source on GitHub ↗

Call a function in a thread and return its result as a coroutine. This uses either :func:`asyncio.to_thread` or :func:`twisted.internet.threads.deferToThread`, depending on whether asyncio support is available. .. versionadded:: 2.15.0

(
    func: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs
)

Source from the content-addressed store, hash-verified

294
295
296async def run_in_thread(
297 func: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs
298) -> _T:
299 """Call a function in a thread and return its result as a coroutine.
300
301 This uses either :func:`asyncio.to_thread` or
302 :func:`twisted.internet.threads.deferToThread`, depending on whether
303 asyncio support is available.
304
305 .. versionadded:: 2.15.0
306 """
307 if is_asyncio_available():
308 return await asyncio.to_thread(func, *args, **kwargs)
309
310 # circular import
311 from scrapy.utils.defer import maybe_deferred_to_future # noqa: PLC0415
312
313 return await maybe_deferred_to_future(deferToThread(func, *args, **kwargs))

Callers 9

wrappedFunction · 0.90
download_requestMethod · 0.90
_get_boto_keyMethod · 0.90
persist_fileMethod · 0.90
stat_fileMethod · 0.90
persist_fileMethod · 0.90
persist_fileMethod · 0.90
stat_fileMethod · 0.90
storeMethod · 0.90

Calls 2

maybe_deferred_to_futureFunction · 0.90
is_asyncio_availableFunction · 0.85

Tested by

no test coverage detected