我有两个文件,实际上是从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 值,而不是根据文档我应该得到的 889 。我不确定我明白为什么会这样。我的超时时间是 10 秒,比文档中的时间长,所以我期待这项工作已经完成。我究竟做错了什么?
1 回答

九州编程
TA贡献1785条经验 获得超4个赞
Redis 服务器是否正在运行?
服务 redis-服务器状态
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
用更简单的函数替换 count_words_at_url,例如
def just_mock(url): time.sleep(5) 返回“{} 的字数是 ??”.format(url)
添加回答
举报
0/150
提交
取消