使用python rq作为队列,但是参考他们的docs没有运行成功文件的组织目录:+ index.py+ test_work| __init__.py| a.pyindex.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基础没有打牢,求解~
1 回答
慕斯王
TA贡献1864条经验 获得超2个赞
你已经 from test_work import a
了,那就直接用 a.count_words_at_url(...)
即可。
至于 ImportError: No module named test_work.a
的错误,那是因为你的 test_work/__init__.py
里面没有 import a
。所以即便你 import test_work
也不能直接 test_work.a.foo
这么用。
添加回答
举报
0/150
提交
取消