(
self,
settings: dict[str, Any] | Settings | None = None,
install_root_handler: bool = True,
)
| 826 | """ |
| 827 | |
| 828 | def __init__( |
| 829 | self, |
| 830 | settings: dict[str, Any] | Settings | None = None, |
| 831 | install_root_handler: bool = True, |
| 832 | ): |
| 833 | super().__init__(settings, install_root_handler) |
| 834 | logger.debug("Using AsyncCrawlerProcess") |
| 835 | self._reactorless_loop: asyncio.AbstractEventLoop | None = None |
| 836 | # We want the asyncio event loop to be installed early, so that it's |
| 837 | # always the correct one. And as we do that, we can also install the |
| 838 | # reactor here. |
| 839 | # The ASYNCIO_EVENT_LOOP setting cannot be overridden by add-ons and |
| 840 | # spiders when using AsyncCrawlerProcess. |
| 841 | loop_path = self.settings["ASYNCIO_EVENT_LOOP"] |
| 842 | if not self.settings.getbool("TWISTED_REACTOR_ENABLED"): |
| 843 | if is_reactor_installed(): |
| 844 | raise RuntimeError( |
| 845 | "TWISTED_REACTOR_ENABLED is False but a Twisted reactor is installed." |
| 846 | ) |
| 847 | self._reactorless_loop = set_asyncio_event_loop(loop_path) |
| 848 | install_reactor_import_hook() |
| 849 | elif is_reactor_installed(): |
| 850 | # The user could install a reactor before this class is instantiated. |
| 851 | # We need to make sure the reactor is the correct one and the loop |
| 852 | # type matches the setting. |
| 853 | verify_installed_reactor(_asyncio_reactor_path) |
| 854 | if loop_path: |
| 855 | verify_installed_asyncio_event_loop(loop_path) |
| 856 | else: |
| 857 | install_reactor(_asyncio_reactor_path, loop_path) |
| 858 | self._initialized_reactor = True |
| 859 | self._reactorless_main_task: asyncio.Future[None] | None = None |
| 860 | |
| 861 | def _stop_dfd(self) -> Deferred[Any]: |
| 862 | return deferred_from_coro(self.stop()) |
nothing calls this directly
no test coverage detected