使用python rq作为队列,但是参考他们的docs没有运行成功
文件的组织目录:
+ index.py
+ test_work
| __init__.py
| a.py
index.py 代码如下:
#coding: utf-8import test_workfrom test_work import afrom redis import Redisfrom rq import Queueif __name__=='__main__': q = Queue(connection = Redis()) x=0 while x<10: x+=1 z=2000200+x print x q.enqueue(a.count_words_at_url,'http://book.douban.com/subject/%d/'%z)
a.py 代码如下:
#coding: utf-8import requests def count_words_at_url(url): resp = requests.get(url) return len(resp.text.split())
在运行以后总是失败,在rq-dashboard中查看到的错误消息:
test_work.a.count_words_at_url('http://book.douban.com/subject/2000201/') from defaultd8d8c5ad-3ff9-4212-8e98-339fc5cfcc31 Failed 11 minutes ago Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/rq-0.3.5-py2.7.egg/rq/worker.py", line 392, in perform_job rv = job.perform() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/rq-0.3.5-py2.7.egg/rq/job.py", line 340, in perform self._result = self.func(*self.args, **self.kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/rq-0.3.5-py2.7.egg/rq/job.py", line 133, in func module = importlib.import_module(module_name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) ImportError: No module named test_work.a
额……python基础没有打牢,求解~
慕斯王
相关分类