-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Remove top-level reactor imports from CrawlerProces/CrawlerRunner examples #6361
Comments
For this we should check if we have |
I think it's enough to move the imports inside blocks so that they only run after the setting is applied (i.e. after If/when that's not possible to do it makes sense to add |
@wRAR I was testing this and noticed that if we have
Because Line 119 in 631fc65
I see Line 79 in 631fc65
runner.crawl from CrawlerRunner theres no way to override this parameter, when is created:
Lines 330 to 334 in 631fc65
P.S: If I switch to Here my snippet: from scrapy import Spider
from scrapy.http import Request
from scrapy.crawler import CrawlerRunner
from scrapy.utils.log import configure_logging
from scrapy.utils.project import get_project_settings
class MySpider1(Spider):
name = "my_spider"
custom_settings = {
"TWISTED_REACTOR": "twisted.internet.asyncioreactor.AsyncioSelectorReactor"
}
def start_requests(self):
yield Request(url="https://httpbin.org/anything")
def parse(self, response):
yield response.json()
class MySpider2(Spider):
name = "my_spider2"
custom_settings = {
"TWISTED_REACTOR": "twisted.internet.asyncioreactor.AsyncioSelectorReactor"
}
def start_requests(self):
yield Request(url="https://httpbin.org/anything")
def parse(self, response):
yield response.json()
configure_logging()
settings = get_project_settings()
runner = CrawlerRunner(settings)
# from scrapy.utils.reactor import install_reactor
# install_reactor("twisted.internet.asyncioreactor.AsyncioSelectorReactor")
runner.crawl(MySpider1)
runner.crawl(MySpider2)
from twisted.internet import reactor
d = runner.join()
d.addBoth(lambda _: reactor.stop())
reactor.run() |
|
Got it, thanks! |
There are several code examples on https://docs.scrapy.org/en/latest/topics/practices.html that have a top-level
from twisted.internet import reactor
, which is problematic (breaks when the settings specify a non-default reactor) and needs to be fixed.The text was updated successfully, but these errors were encountered: