Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aio-libs/janus
Thread-safe asyncio-aware queue for Python
https://github.com/aio-libs/janus
asyncio mypy queue threadsafe
Last synced: 1 day ago
JSON representation
Thread-safe asyncio-aware queue for Python
- Host: GitHub
- URL: https://github.com/aio-libs/janus
- Owner: aio-libs
- License: apache-2.0
- Created: 2015-06-08T15:45:28.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-23T05:01:32.000Z (12 days ago)
- Last Synced: 2024-10-29T15:18:44.696Z (5 days ago)
- Topics: asyncio, mypy, queue, threadsafe
- Language: Python
- Homepage:
- Size: 479 KB
- Stars: 818
- Watchers: 21
- Forks: 49
- Open Issues: 12
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
- best-of-python - GitHub - 21% open · ⏱️ 06.06.2024): (Data Structures)
README
=======
janus
=======
.. image:: https://github.com/aio-libs/janus/actions/workflows/ci.yml/badge.svg
:target: https://github.com/aio-libs/janus/actions/workflows/ci.yml
.. image:: https://codecov.io/gh/aio-libs/janus/branch/master/graph/badge.svg
:target: https://codecov.io/gh/aio-libs/janus
.. image:: https://img.shields.io/pypi/v/janus.svg
:target: https://pypi.python.org/pypi/janus
.. image:: https://badges.gitter.im/Join%20Chat.svg
:target: https://gitter.im/aio-libs/Lobby
:alt: Chat on GitterMixed 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
=============.. code:: python
import asyncio
import janusdef 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)
.. _asyncio: https://docs.python.org/3/library/asyncio.html