AsyncThread
Index
Methods
__init__
Parameters
optionaldefault_timeout: timedelta = timedelta(seconds=60)
Returns None
close
Close the event loop and its thread gracefully.
This method cancels all pending tasks, stops the event loop, and waits for the thread to exit. If the thread does not exit within the given timeout, a forced shutdown is attempted.
Parameters
optionaltimeout: timedelta | None = None
The maximum time to wait for the event loop thread to exit. Pass
Noneto use thedefault_timeoutpassed to the constructor.
Returns None
run_coro
Run a coroutine on an event loop running in a separate thread.
This method schedules the coroutine to run on the event loop and blocks until the coroutine completes or the specified timeout is reached.
Parameters
coro: Coroutine
The coroutine to run.
optionaltimeout: timedelta | Literal[default] = 'default'
The maximum time to wait for the coroutine to finish. Pass
'default'to use thedefault_timeoutpassed to the constructor.
Returns Any
The result returned by the coroutine.
Run an asyncio event loop in a dedicated background thread.
This lets synchronous Scrapy callbacks drive asynchronous Apify and Crawlee coroutines. The scheduler and the HTTP cache storage each own their own
AsyncThread, so the request queue and the key-value store never share an event loop; they only share the read-only globalConfiguration. A single shared loop would also work but would couple their lifecycles.