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了。








 

你可能感兴趣的:(functions)