A persistent multi-producer multi-consumer gevent queue
Project description
gevent-queue is a lightweight, stateful multi-producer and multi-consumer queue. It was designed to work inside gevent-based web apps (especially Flask) so that you only need a single process. If you later wish to scale, you can easily spawn separate worker processes.
gevent-queue supports Redis to persist enqueued messages.
Installing
Install and update using pip:
pip install -U gevent-queue
Usage Examples
Using queues:
import redis
import gevent_queue
r = redis.Redis()
q = gevent_queue.Queue(r, "myqueue")
q.put("foo")
q.put("bar")
print(q.get())
q.task_done()
print(q.get())
q.task_done()
Using locks:
import redis
import time
import gevent_queue
import threading
r = redis.Redis()
l = gevent_queue.Lock(r, "mylock")
def do_work():
with l:
print("begin")
time.sleep(1)
print("end")
worker1 = threading.Thread(target=do_work)
worker2 = threading.Thread(target=do_work)
worker1.start()
worker2.start()
worker1.join()
worker2.join()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gevent-queue-0.1.1.tar.gz
(5.5 kB
view hashes)