gpt4 book ai didi

python - 为什么我得到 '_SIGCHLDWaker' object has no attribute 'doWrite' in Scrapy?

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:39 34 4
gpt4 key购买 nike

我在 Celery 中使用 Scrapy 蜘蛛,我随机得到这种错误

Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/twisted/python/log.py", line 103, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/usr/lib/python2.7/site-packages/twisted/python/log.py", line 86, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/lib/python2.7/site-packages/twisted/python/context.py", line 122, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/lib/python2.7/site-packages/twisted/python/context.py", line 85, in callWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "/usr/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 602, in _doReadOrWrite
why = selectable.doWrite()
exceptions.AttributeError: '_SIGCHLDWaker' object has no attribute 'doWrite'

我正在使用:

celery==3.1.19
Django==1.9.4
Scrapy==1.3.0

这就是我在 Celery 中运行 Scrapy 的方式:

from billiard import Process
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings

class MyCrawlerScript(Process):
def __init__(self, **kwargs):
Process.__init__(self)
settings = get_project_settings('my_scraper')
self.crawler = CrawlerProcess(settings)
self.spider_name = kwargs.get('spider_name')
self.kwargs = kwargs

def run(self):
self.crawler.crawl(self.spider_name, qwargs=self.kwargs)
self.crawler.start()

def my_crawl_manager(**kwargs):
crawler = MyCrawlerScript(**kwargs)
crawler.start()
crawler.join()

在 celery 任务中,我调用:

my_crawl_manager(spider_name='my_spider', url='www.google.com/any-url-here')

请问为什么会这样?

P.S: 我又问了一个问题Why I am Getting KeyError in Scrapy?不知道有没有相似之处

最佳答案

我遇到了同样的问题。我在一个复杂的应用程序中工作,同时使用 asynciomultiprocessing、Twisted 和 Scrapy。

我的解决方案是使用 asyncioreactor,通过在 scrapy 中的任何导入之前安装备用 react 器:

from twisted.internet import asyncioreactor
asyncioreactor.install()

from scrapy import stuff
# ...

关于python - 为什么我得到 '_SIGCHLDWaker' object has no attribute 'doWrite' in Scrapy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42347121/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com