Skip to main content

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.


Build Status codecov PyPI version

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

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.

more examples

Release log

License

MIT

Project details


Release history Release notifications

This version

0.0.5

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for wukongqueue, version 0.0.5
Filename, size File type Python version Upload date Hashes
Filename, size wukongqueue-0.0.5-py3-none-any.whl (15.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size wukongqueue-0.0.5.tar.gz (13.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page