Mixed sync-async queue, supposed to be used for communicating between classic synchronous (threaded) code and asynchronous (in terms of asyncio) one.
Like Janus god the queue object from the library has two faces: synchronous and asynchronous interface.
Synchronous is fully compatible with standard queue, asynchronous one follows asyncio queue design.
Usage
Three queues are available:
Queue
LifoQueue
PriorityQueue
Each has two properties: sync_q and async_q.
Use the first to get synchronous interface and the second to get asynchronous one.
Example
import asyncio
import janus
def threaded(sync_q: janus.SyncQueue[int]) -> None:
for i in range(100):
sync_q.put(i)
sync_q.join()
async def async_coro(async_q: janus.AsyncQueue[int]) -> None:
for i in range(100):
val = await async_q.get()
assert val == i
async_q.task_done()
async def main() -> None:
queue: janus.Queue[int] = janus.Queue()
loop = asyncio.get_running_loop()
fut = loop.run_in_executor(None, threaded, queue.sync_q)
await async_coro(queue.async_q)
await fut
await queue.aclose()
asyncio.run(main())
Limitations
This library is built using a classic thread-safe design. The design is time-tested, but has some limitations.
Once you are done working with a queue, you must properly close it using aclose(). This is because this library creates new tasks to notify other threads. If you do not properly close the queue, asyncio may generate error messages.
The library has quite good performance only when used as intended, that is, for communication between synchronous code and asynchronous one. For sync-only and async-only cases, use queues from queue and asyncio queue modules, otherwise the slowdown can be significant.
You cannot use queues for communicating between two different event loops because, like all asyncio primitives, they bind to the current one.
Development status is production/stable. The janus library is maintained to support the latest versions of Python and fixes, but no major changes will be made. If your application is performance-sensitive, or if you need any new features such as anyio support, try the experimental culsans library as an alternative.
Communication channels
GitHub Discussions: https://github.com/aio-libs/janus/discussions
Feel free to post your questions and ideas here.
gitter chat https://gitter.im/aio-libs/Lobby
License
janus library is offered under Apache 2 license.
Thanks
The library development is sponsored by DataRobot (https://datarobot.com)
Release files for janus 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| janus-2.0.0.tar.gz | 22.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| janus-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.1 kB
Release files / janus-2.0.0.tar.gz
| Download URL | janus-2.0.0.tar.gz |
|---|---|
| Size | 22.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0970f38e0e725400496c834a368a67ee551dc3b5ad0a257e132f5b46f2e77770
|
|
BLAKE2b-256 checksum How to use checksums |
d87f69884b6618be4baf6ebcacc716ee8680a842428a19f403db6d1c0bb990aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 13, 2024.
Transparency logRelease files / janus-2.0.0-py3-none-any.whl
| Download URL | janus-2.0.0-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7e6449d34eab04cd016befbd7d8c0d8acaaaab67cb59e076a69149f9031745f9
|
|
BLAKE2b-256 checksum How to use checksums |
683465604740edcb20e1bda6a890348ed7d282e7dd23aa00401cbe36fd0edbd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 13, 2024.
Transparency log