Collections of queues to handle sequentially tagged objects
Project description
SeqQueue
Python queue implementations for incrementally indexed, sequential data. SeqQueue makes sure any get()
call returnes the next (index, item)
pair from the queue.
Installation
pip3 install seqqueue
Install from source:
git clone https://github.com/highvight/seqqueue
cd seqqueue
pip3 install .
To run tests and benchmarks:
pip3 install .[testing]
Or just copy and paste and one of the classes to your project
Usage
from seqqueue import SeqQueue
q = SeqQueue(start_index=0)
q.put((1, "1"))
q.put((2, "2"))
q.put((0, "0"))
print(q.get()) # (0, "0")
print(q.get()) # (1, "1")
print(q.get()) # (2, "2")
Note that Empty and Full exceptions are raised with respect to the index
from seqqueue import SeqQueue
q = SeqQueue(start_index=0, maxsize=2)
q.put((1,"1"))
print(q.qsize()) # 1
q.get(block=False) # Raises Empty, index=0 not available
q.put((2,"2"), block=False) # Raises Full, index=2 > maxindex
For multiprocessing, use multiprocessing.Manager
import multiprocessing as mp
from seqqueue import SeqQueue
manager = mp.Manager()
q = manager.SeqQueue(start_index=0)
Benchmark
Make sure to install [testing]
(see Usage). In the project root run:
pytest benchmark
This will run some benchmarks for concurrent put()
and get()
calls in comparison to PriorityQueue
from the standard library. As you can see, depending on the number of threads and maxsize of the queue, keeping incremental index order comes at a cost. For instance, for a maxsize=8
and n_threads=[1,2,20]
, on my Laptop, SeqQeue is ~ 2x-3x slower:
put=1, get=1 | put=2, get=2 | put=20, get=20 | |
---|---|---|---|
PriorityQueue | 31.8575 (1.0) | 56.9946 (1.79) | 76.1026 (2.39) |
SeqQeue | 59.4795 (1.87) | 82.9272 (2.60) | 197.6096 (6.20) |
If you find faster implementations please open a MR!
In real-world applications the costs of queue management are often negligible. Adjust the benchmark scripts with your real data and thread target functions to find out :)
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
Built Distribution
File details
Details for the file seqqueue-0.4.tar.gz
.
File metadata
- Download URL: seqqueue-0.4.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c2696388529224bfdc30a21548488fe41170ce1c763ac5a5413a286288e41f0 |
|
MD5 | 8f538b257d41d3e21fd0561337fb26dc |
|
BLAKE2b-256 | a50a90811285a006bcb2dea454ac6f9e5a6ddc953c7e39ddb4b30a602fdb4377 |
File details
Details for the file seqqueue-0.4-py3-none-any.whl
.
File metadata
- Download URL: seqqueue-0.4-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9475910712c134e4aa8c4fde688713975166f56066cfaca32f3bcc75bb00cab |
|
MD5 | 2574e959c3229330e6bdf2a3d74ec8ee |
|
BLAKE2b-256 | f736d47e710285a49465162a482cda66fff709f810c16f06c7a092bdadf15e30 |