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()
Using cron expressions:
import gevent_queue
import datetime
date = datetime.datetime(2021, 1, 23, 11, 54)
assert gevent_queue.cron_matches("* * * * *", date)
assert gevent_queue.cron_matches("40-59 * * * *", date)
assert gevent_queue.cron_matches("* 9-16/2 * * *", date)
start = datetime.datetime(2021, 1, 23, 11, 54)
end = datetime.datetime(2021, 1, 28, 0, 0)
assert gevent_queue.cron_occurs_between("54 11 23 01 6", start, end)
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.2.tar.gz
(6.4 kB
view hashes)