python redis-queue:文档中的简单示例不起作用

我有两个文件,实际上是从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

某处.py


import requests

def count_words_at_url(url):

    print("hello?")

    resp = requests.get(url)

    return len(resp.text.split())

我跑了app.py,我得到的输出是 2 None 值,而不是根据文档我应该得到的 889 。


我不确定我明白为什么会这样。我的超时时间是 10 秒,比文档中的时间长,所以我期待这项工作已经完成。


我究竟做错了什么?


慕标琳琳
浏览 152回答 1
1回答

九州编程

Redis 服务器是否正在运行?服务 redis-服务器状态rq worker 正在运行吗?请求信息如果没有工人运行,那么rq worker # run this under the same directory of your project18:44:54 RQ worker 'rq:worker:ubuntu.45276' started, version 0.12.018: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)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python