使用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
提交
取消