New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] wrong reactor installed error #4406
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4406 +/- ##
==========================================
+ Coverage 84.57% 84.71% +0.13%
==========================================
Files 166 166
Lines 9872 9915 +43
Branches 1467 1474 +7
==========================================
+ Hits 8349 8399 +50
+ Misses 1268 1258 -10
- Partials 255 258 +3
|
I think you've missed several top-level imports, for example one in https://github.com/scrapy/scrapy/blob/master/scrapy/core/downloader/__init__.py How did you search for them? |
docs/topics/settings.rst
Outdated
:mod:`~twisted.internet.reactor` imports in project files & imported | ||
3rd party libraries may also raise :exc:`Exception` as Twisted will install the | ||
default reactor before scrapy installs reactor specified in | ||
:setting:`TWISTED_REACTOR` leading to a mismatch in installed reactor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those top-level imports won't raise an exception, Scrapy will, when it checks which reactor is installed, so this can be rephrased.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I will change it to:
CrawlerRunner
raises Exception
if the installed reactor does not match the TWISTED_REACTOR
setting; therefore, having top-level twisted.internet.reactor
imports in project files & imported 3rd party libraries will make Scrapy raise Exception
when it checks which reactor is installed.
@wRAR My bad. I will fix this now. I made a mistake in my search earlier. Now I am searching for Also, I am a bit confused about some of the import such as those in as these are used either at top level or inside a Should I move top-level imports in tests (test_downloadermiddleware_robotstxt.py, test_engine.py, test_pipeline_media.py, test_utils_defer.py, test_utils_signal.py, test_webclient.py) as well? |
- Error occured when TWISTED_REACTOR in settings.py was set - remove all top-level imports for twisted.internet.reactor
- update docs for TWISTED_REACTOR in settings.rst
@wRAR Also, @nyov suggested an idea to "replace the twisted.internet.reactor function with a custom lazy-loading reactor-loading function instead". I think this is feasible and mentioned a solution using |
The reactor in tests is currently installed early, via the pytest-twisted plugin, so I think there is currently no need to do it.
I don't currently see benefits of doing this, especially as it won't directly help with user or 3rd party code, but it's nice to have this as an option in case we need it. |
@wRAR Thanks for you reply. I have refactored
Should I add the |
@adityaa30 Since this is something we would like to fix rather soon, and to keep things simple, I think it’s best not to address the lazy loading in this issue. We can address it later in a different issue if we see a use for it. A |
Sure. |
@wRAR @Gallaecio I am not really sure what happened here. TravisCI passed the tests at 8bbc445 (Link to result) but after 762a7e3 the tests have started to fail. What could be the possible reason? |
It is not your code, it looks like it is happening in |
Thanks! |
docs/settings.rst
Fixes #4401