我有兩個文件,實際上是從http://python-rq.org/docs/復制粘貼的:應用程序 from rq import Queue from redis import Redis from somewhere import count_words_at_url import time # Tell RQ what Redis connection to use redis_conn = Redis() q = Queue(connection=redis_conn) # no args implies the default queue print(redis_conn) # Delay execution of count_words_at_url('http://nvie.com') job = q.enqueue(count_words_at_url, 'http://nvie.com') print(job.result) # => None # Now, wait a while, until the worker is finished time.sleep(10) print(job.result) # => 889某處.pyimport requestsdef count_words_at_url(url): print("hello?") resp = requests.get(url) return len(resp.text.split())我跑了app.py,我得到的輸出是 2 None 值,而不是根據(jù)文檔我應該得到的 889 。我不確定我明白為什么會這樣。我的超時時間是 10 秒,比文檔中的時間長,所以我期待這項工作已經(jīng)完成。我究竟做錯了什么?
1 回答

九州編程
TA貢獻1785條經(jīng)驗 獲得超4個贊
Redis 服務器是否正在運行?
服務 redis-服務器狀態(tài)
rq worker 正在運行嗎?
請求信息
如果沒有工人運行,那么
rq worker # run this under the same directory of your project
18:44:54 RQ worker 'rq:worker:ubuntu.45276' started, version 0.12.0
18:44:54 *** Listening on default...
18:44:54 Cleaning registries for queue: default
用更簡單的函數(shù)替換 count_words_at_url,例如
def just_mock(url): time.sleep(5) 返回“{} 的字數(shù)是 ??”.format(url)
添加回答
舉報
0/150
提交
取消