当前位置:编程学习 > 网站相关 >>

Python队列服务 Python RQ Functions from the __main__ module cannot be processed by workers.

在使用Python队列服务 Python RQ 时候的报错:
 
 
Functions from the __main__ module cannot be processed by workers.
 
 
原因:
 
 work 不能和job放在同一模块中,否则程序会报错
 
 
 
解决:
 
把使用rq的代码文件job.py中的
 
task_queue.enqueue(count_words_at_url,"http://messense.me/redis-queue-python-rq-usage.html")
 
中的第一个参数(一个函数count_words_at_url)存放到另外一个python文件中:some.py:
 
 
 
# -*- coding:utf-8 -*-
from rq import Queue
from rq import use_connection
import os,redis,requests
def count_words_at_url(url):
    resp = requests.get(url)
    return len(resp.text.split())
 
 
 
在job.py中增加:
 
import some                    #some即为some.py的文件名称
 
即可使用count_words_at_url了。
 
 
 
 
 
 
 
 
 
补充:Web开发 , Python ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,