janus 2.0.0
pip install janus
Released:
Mixed sync-async queue to interoperate between asyncio tasks and classic threads
Navigation
Verified details
These details have been verified by PyPIProject links
Owner
GitHub Statistics
Maintainers
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: Apache Software License (Apache 2)
- Author: Andrew Svetlov <andrew.svetlov@gmail.com>
- Tags janus, queue, asyncio
- Requires: Python >=3.9
Classifiers
- Development Status
- Framework
- Intended Audience
- License
- Operating System
- Programming Language
- Topic
Project description
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)
Project details
Verified details
These details have been verified by PyPIProject links
Owner
GitHub Statistics
Maintainers
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: Apache Software License (Apache 2)
- Author: Andrew Svetlov <andrew.svetlov@gmail.com>
- Tags janus, queue, asyncio
- Requires: Python >=3.9
Classifiers
- Development Status
- Framework
- Intended Audience
- License
- Operating System
- Programming Language
- Topic
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 janus-2.0.0.tar.gz
.
File metadata
- Download URL: janus-2.0.0.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0970f38e0e725400496c834a368a67ee551dc3b5ad0a257e132f5b46f2e77770 |
|
MD5 | 7c8ec257be4e90abc47a7df47df88436 |
|
BLAKE2b-256 | d87f69884b6618be4baf6ebcacc716ee8680a842428a19f403db6d1c0bb990aa |
Provenance
The following attestation bundles were made for janus-2.0.0.tar.gz
:
Publisher:
ci.yml
on aio-libs/janus
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
janus-2.0.0.tar.gz
- Subject digest:
0970f38e0e725400496c834a368a67ee551dc3b5ad0a257e132f5b46f2e77770
- Sigstore transparency entry: 155188013
- Sigstore integration time:
- Permalink:
aio-libs/janus@652bc8d2bc1e5d83e0761438b82bd402f6cc9659
- Branch / Tag:
refs/tags/v2.0.0
- Owner: https://github.com/aio-libs
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
ci.yml@652bc8d2bc1e5d83e0761438b82bd402f6cc9659
- Trigger Event:
push
- Statement type:
File details
Details for the file janus-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: janus-2.0.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e6449d34eab04cd016befbd7d8c0d8acaaaab67cb59e076a69149f9031745f9 |
|
MD5 | 5f2932b1e695451d8b7d7537bbeaf846 |
|
BLAKE2b-256 | 683465604740edcb20e1bda6a890348ed7d282e7dd23aa00401cbe36fd0edbd9 |
Provenance
The following attestation bundles were made for janus-2.0.0-py3-none-any.whl
:
Publisher:
ci.yml
on aio-libs/janus
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
janus-2.0.0-py3-none-any.whl
- Subject digest:
7e6449d34eab04cd016befbd7d8c0d8acaaaab67cb59e076a69149f9031745f9
- Sigstore transparency entry: 155188014
- Sigstore integration time:
- Permalink:
aio-libs/janus@652bc8d2bc1e5d83e0761438b82bd402f6cc9659
- Branch / Tag:
refs/tags/v2.0.0
- Owner: https://github.com/aio-libs
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
ci.yml@652bc8d2bc1e5d83e0761438b82bd402f6cc9659
- Trigger Event:
push
- Statement type: