Installs the :mod:`~twisted.internet.reactor` with the specified import path. Also installs the asyncio event loop with the specified import path if the asyncio reactor is enabled
(reactor_path: str, event_loop_path: str | None = None)
| 110 | |
| 111 | |
| 112 | def install_reactor(reactor_path: str, event_loop_path: str | None = None) -> None: |
| 113 | """Installs the :mod:`~twisted.internet.reactor` with the specified |
| 114 | import path. Also installs the asyncio event loop with the specified import |
| 115 | path if the asyncio reactor is enabled""" |
| 116 | reactor_class = load_object(reactor_path) |
| 117 | if reactor_class is asyncioreactor.AsyncioSelectorReactor: |
| 118 | set_asyncio_event_loop_policy() |
| 119 | with suppress(error.ReactorAlreadyInstalledError): |
| 120 | event_loop = set_asyncio_event_loop(event_loop_path) |
| 121 | asyncioreactor.install(eventloop=event_loop) |
| 122 | else: |
| 123 | *module, _ = reactor_path.split(".") |
| 124 | installer_path = [*module, "install"] |
| 125 | installer = load_object(".".join(installer_path)) |
| 126 | with suppress(error.ReactorAlreadyInstalledError): |
| 127 | installer() |
| 128 | |
| 129 | |
| 130 | def _get_asyncio_event_loop() -> AbstractEventLoop: |