From b7fefbab252afb65ef0c5e11306aee0e2a80e8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Chaves?= Date: Fri, 4 Aug 2023 09:26:14 +0200 Subject: [PATCH] Expand on the potential issue of switching reactors --- README.rst | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index f957e1ec..f6f9e53a 100644 --- a/README.rst +++ b/README.rst @@ -101,12 +101,24 @@ To enable this plugin: ``"twisted.internet.asyncioreactor.AsyncioSelectorReactor"``. .. note:: On existing projects that were not using the asyncio Twisted - reactor and make use of advanced Scrapy features, like interacting with - the Scrapy engine at run time, switching reactors may require - additional changes. If that is your case, see - `asyncio `_ in - the Scrapy documentation, specially `Awaiting on Deferreds - `_. + reactor, your existing code may need changes, such as: + + - Moving some module-level Twisted imports to the method or function + definitions where they are used, or `installing the asyncio reactor + `_ + before those imports happen. + + Some Twisted imports install the default, non-async Twisted + reactor as a side effect. Once a reactor is installed, it cannot be + changed for the whole run time. + + - `Converting Twisted Deferreds into asyncio Futures + `_. + + Note that you might be using Deferreds without realizing it through + some Scrapy functions and methods. For example, when you yield the + return value of ``self.crawler.engine.download()`` from a spider + callback, you are yielding a Deferred. - Set `your Zyte API key `_ as