An utility for asyncio.Queue.
Project description
wcpan.queue
An utility for asyncio.Queue
.
Example
from wcpan.queue import AioQueue
async def task() -> int:
...
async def amain():
# Creates a priority queue.
# Use AioQueue.fifo() for FIFO and AioQueue.lifo() for LIFO.
with AioQueue[int].priority() as queue:
# Push a task which priority is 1, lesser number has higher priority.
# Default is 0.
# Priority is ignored for FIFO and LIFO queues.
await queue.push(task(), 1)
# Spawns 8 consumers to consume the queue.
# The default is 1.
await queue.consume(8)
await queue.push(task())
# Or collect the results like this:
async for result in queue.collect(8):
...
# If any error occurs, the context manager will cleanup all coroutines.
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
wcpan_queue-7.2.1.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for wcpan_queue-7.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1688ac9727ad943d88972cc5cc591918e344fd499893f7f81cb264fc6489eba9 |
|
MD5 | b0392c693ac77a4828fa93c075301eef |
|
BLAKE2b-256 | e673ec674e250715a2c0a3f08f4e2864032b15e1a69809c73b05a5c3364e2534 |