python redis-queue:文档不工作的简单示例
python redis-queue: Simple example from documentaion not working
我有两个文件,从字面上复制粘贴 http://python-rq.org/docs/:
app.py
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
somewhere.py
import requests
def count_words_at_url(url):
print("hello?")
resp = requests.get(url)
return len(resp.text.split())
I 运行 app.py
,我得到的输出是 2 None 值,而不是根据文档我应该得到的 889。
我不确定我明白为什么会这样。我的超时时间是 10 秒,它比文档中的时间长,所以我期待工作完成。
我做错了什么?
是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)
return "count words for {} is ??".format(url)
我有两个文件,从字面上复制粘贴 http://python-rq.org/docs/:
app.py
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
somewhere.py
import requests
def count_words_at_url(url):
print("hello?")
resp = requests.get(url)
return len(resp.text.split())
I 运行 app.py
,我得到的输出是 2 None 值,而不是根据文档我应该得到的 889。
我不确定我明白为什么会这样。我的超时时间是 10 秒,它比文档中的时间长,所以我期待工作完成。
我做错了什么?
是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) return "count words for {} is ??".format(url)