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








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章