Schedule the coroutine as a task or a Deferred. This doesn't store the reference to the task/Deferred, so a better alternative is calling :func:`scrapy.utils.defer.deferred_from_coro`, keeping the result, and adding proper exception handling (e.g. errbacks) to it.
(coro: Coroutine[Any, Any, Any])
| 525 | |
| 526 | |
| 527 | def _schedule_coro(coro: Coroutine[Any, Any, Any]) -> None: |
| 528 | """Schedule the coroutine as a task or a Deferred. |
| 529 | |
| 530 | This doesn't store the reference to the task/Deferred, so a better |
| 531 | alternative is calling :func:`scrapy.utils.defer.deferred_from_coro`, |
| 532 | keeping the result, and adding proper exception handling (e.g. errbacks) to |
| 533 | it. |
| 534 | """ |
| 535 | if not is_asyncio_available(): |
| 536 | Deferred.fromCoroutine(coro) |
| 537 | return |
| 538 | loop = asyncio.get_event_loop() |
| 539 | loop.create_task(coro) # noqa: RUF006 |
| 540 | |
| 541 | |
| 542 | @overload |