Skip to main content

k3priorityqueue

Action-CI Documentation Status Package

priorityQueue is a queue with priority support

k3priorityqueue is a component of pykit3 project: a python3 toolkit set.

PriorityQueue is a queue with priority support:

The numbers of items it pops from each producer matches exactly the ratio of their priority: If the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long enough, it is expected that the number of items popped from A, B and C are 1:3:7.

import k3priorityqueue

producers = ( # id, priority, iterable (1, 1, [1] * 10), (2, 2, [2] * 10), (3, 3, [3] * 10),

)

pq = k3priorityqueue.PriorityQueue()

for pid, prio, itr in producers: pq.add_producer(pid, prio, itr)

count = {}

for _ in range(12): val = pq.get() count[val] = count.get(val, 0) + 1 print(val)

print('respect priority ratio: counts:', repr(count))

while True: try: val = pq.get() except k3priorityqueue.Empty as e: break

count[val] = count.get(val, 0) + 1
print(val)

print('consumed all: counts:', repr(count))

Install

pip install k3priorityqueue

Synopsis

import k3priorityqueue

producers = (
    # id, priority, iterable
    (1, 1, [1] * 10),
    (2, 2, [2] * 10),
    (3, 3, [3] * 10),
)
pq = k3priorityqueue.PriorityQueue()
for pid, prio, itr in producers:
    pq.add_producer(pid, prio, itr)

count = {}
for _ in range(12):
    val = pq.get()
    count[val] = count.get(val, 0) + 1
    print(val)

print("respect priority ratio: counts:", repr(count))

while True:
    try:
        val = pq.get()
    except k3priorityqueue.Empty:
        break
    count[val] = count.get(val, 0) + 1
    print(val)

print("consumed all: counts:", repr(count))

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Metadata

Release files for k3priorityqueue 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3priorityqueue 0.1.8
File Size Uploaded
k3priorityqueue-0.1.8.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for k3priorityqueue 0.1.8
File Interpreter ABI Platform
k3priorityqueue-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / k3priorityqueue-0.1.8.tar.gz

Download URL k3priorityqueue-0.1.8.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4bc09e36437ea7a2166e2b008ba6f07083db6018c57c32ce9238ff7da80df8c2
BLAKE2b-256 checksum
How to use checksums
cd88571a4c90cd462d95dedabedfdfbb73cb777c5973d954429dae8ce96b20b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3priorityqueue-0.1.8-py3-none-any.whl

Download URL k3priorityqueue-0.1.8-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfb746a4214d03318a67d74fac870f6d43d5f69ddb1f01df57dd42b2d41c97aa
BLAKE2b-256 checksum
How to use checksums
f9d9900c187d6c0c174f942c1a03a0e618180f427a522af62d40056425671972
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

0.1.10

2 release files

0.1.9

2 release files

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page