Check whether the installed reactor is :class:`~twisted.internet.asyncioreactor.AsyncioSelectorReactor`. Raise a :exc:`RuntimeError` if no reactor is installed. In a future Scrapy version, when Scrapy supports running without a Twisted reactor, this function won't be useful for checkin
()
| 216 | |
| 217 | |
| 218 | def is_asyncio_reactor_installed() -> bool: |
| 219 | """Check whether the installed reactor is :class:`~twisted.internet.asyncioreactor.AsyncioSelectorReactor`. |
| 220 | |
| 221 | Raise a :exc:`RuntimeError` if no reactor is installed. |
| 222 | |
| 223 | In a future Scrapy version, when Scrapy supports running without a Twisted |
| 224 | reactor, this function won't be useful for checking if it's possible to use |
| 225 | asyncio features, so the code that that doesn't directly require a Twisted |
| 226 | reactor should use :func:`scrapy.utils.asyncio.is_asyncio_available` |
| 227 | instead of this function. |
| 228 | |
| 229 | .. versionchanged:: 2.13 |
| 230 | In earlier Scrapy versions this function silently installed the default |
| 231 | reactor if there was no reactor installed. Now it raises an exception to |
| 232 | prevent silent problems in this case. |
| 233 | """ |
| 234 | if not is_reactor_installed(): |
| 235 | raise RuntimeError( |
| 236 | "is_asyncio_reactor_installed() called without an installed reactor." |
| 237 | ) |
| 238 | |
| 239 | from twisted.internet import reactor |
| 240 | |
| 241 | return isinstance(reactor, asyncioreactor.AsyncioSelectorReactor) |