Python簡單作業隊列系統:RQ
RQ (Redis Queue) 是一個簡單的 Python 庫,用于實現作業的隊列,并在后臺進行處理。后端基于 Redis ,可方便集成到 Web 應用中,要求 Redis >= 2.6.0。
Getting started
首先,運行一個Redis服務器:
$ redis-server
將 jobs 加到隊列中
import requests def count_words_at_url(url): """Just an example function that's called async.""" resp = requests.get(url) return len(resp.text.split())
然后,創建一個RQ列隊:
from rq import Queue, use_connection use_connection() q = Queue()
And enqueue the function call:
from my_module import count_words_at_url result = q.enqueue(count_words_at_url, 'http://nvie.com')
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!