Mixed sync-async queue to interoperate between asyncio tasks and classic threads
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 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
queue.close()
await queue.wait_closed()
asyncio.run(main())
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
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-1.1.0.tar.gz
.
File metadata
- Download URL: janus-1.1.0.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0634df8b2b31f8afda4311abcf7fea912686fef717d13769eeaa01ae08d2b84c |
|
MD5 | 0e3053f8b41e447e3cabed4075ac9116 |
|
BLAKE2b-256 | 4550112a19f28a11b545c4c95de29c50a06fa9381a2432eaabbf9316bbd4e046 |
Provenance
File details
Details for the file janus-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: janus-1.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a3daf0f1a16abda1a7c976e28dc1f6caf3b8d1de9b8c93b2ea84de424de7705 |
|
MD5 | e2f5169c0c4a7a4dff54eb0745eb10a7 |
|
BLAKE2b-256 | b7f37a4e99ce86e9ec5851e930d8fd218b34b741d2663cde895a4804e4bd460f |