A lightweight and convenient cross process FIFO queue service based on TCP protocol.
Project description
wukongqueue
A lightweight and convenient cross process FIFO queue service based on TCP protocol.
wukongqueue's local queue service is developed based on Python standard library
queue
.
Features
- Fast (directly based on tcp long-running connection)
- Multi-producer and Multi-consumer from different threads/processes
- Easy to use, APIs' usage like stdlib
queue
- Allow to set authentication key for connection to server
Requirements
- Python3.5+ (need type hints)
Install
pip install wukongqueue
Examples
server.py
from wukongqueue import WuKongQueue
import time
# start a queue server
svr = WuKongQueue(host='127.0.0.1',port=666,max_conns=10,max_size=0)
with svr:
print("svr is started!")
svr.put(b"1")
time.sleep(10)
svr.put(b"2")
print("wait for clients...")
time.sleep(10)
print("putted b'1' and b'2', svr closed!")
clientA.py
from wukongqueue import WuKongQueueClient
client = WuKongQueueClient(host='127.0.0.1', port=666)
with client:
print("got",client.get()) # b"1"
client.task_done()
print("after 10 seconds, got",client.get(block=True)) # wait for 3 seconds, then print b"2"
client.task_done()
print("clientA: all task done!")
clientB.py
from wukongqueue import WuKongQueueClient
client = WuKongQueueClient(host='127.0.0.1', port=666)
with client:
client.join()
print("clientB all task done!")
Then start these three program in order, you can see the following print:
# server.py print firstly
svr is started! (immediately)
wait for clients... (+3 seconds)
putted b'1' and b'2', svr closed! (+10s)
# clientA print secondly
got b'1' (immediately)
after 3 seconds, got b'2' (+3 seconds)
clientA: all task done!
# clientB print lastly
clientB all task done! (same as clientA last print)
Currently, the get and put methods on the server and client only support bytes and strings, but in the end, they still communicate between processes in bytes.
The server's usage of with is exactly the same.
Release log
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
wukongqueue-0.0.5.tar.gz
(13.0 kB
view hashes)
Built Distribution
Close
Hashes for wukongqueue-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b7d9295972103c569ed445055442c45e226bfb784ce5221439cfbfa4d8f47b0 |
|
MD5 | 39a871c609eed595ca65e5c1f8426cb4 |
|
BLAKE2b-256 | aaa0c7d183231cba7991bb0cfd2a61126c24ea1927650908369bec28eb9d32c4 |