janus is a Python library providing mixed synchronous and asynchronous queues to facilitate communication between classic threaded code and asyncio tasks. It offers `Queue`, `LifoQueue`, and `PriorityQueue` implementations, each with distinct synchronous (`.sync_q`) and asynchronous (`.async_q`) interfaces. The current version is 2.0.0, and the library is actively maintained to support the latest Python versions.
pip install janusVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `janus.Queue` to allow a synchronous thread to put items into a queue while an asynchronous coroutine concurrently consumes them. It highlights the use of `.sync_q` and `.async_q` interfaces and the important `aclose()` call for cleanup.
Update `try...except RuntimeError` blocks to catch `janus.AsyncQueueShutDown` or `janus.SyncQueueShutDown` when dealing with queue shutdowns. Adjust code that previously relied on `task_done()` or `join()` raising exceptions after a queue is closed.
Upgrade your Python environment to 3.9 or a newer supported version.
Remove the `loop` argument when creating `janus.Queue` instances (e.g., `janus.Queue(loop=my_loop)` should become `janus.Queue()`). Ensure queue creation happens within an `asyncio` context where `asyncio.get_running_loop()` returns a valid loop.
Always include `await queue.aclose()` in your cleanup logic, typically at the end of your `async` entry point, to properly shut down internal resources.
Evaluate your use case: if communication is strictly sync-to-sync or async-to-async, prefer Python's built-in `queue` or `asyncio.Queue` modules for better performance.
Ensure that `janus` queues are created and accessed within the context of a single asyncio event loop. For inter-process or inter-event loop communication, consider higher-level mechanisms like multiprocessing queues or message brokers.
Run `pip install janus` in your terminal to install the library.
Ensure that each `janus.Queue` is created and used exclusively within the same `asyncio` event loop, typically by creating it in the thread where its asynchronous interface will be primarily accessed.
Access the `put()` or `get()` methods via the appropriate interface: `queue.sync_q.put(...)` for synchronous operations or `await queue.async_q.put(...)` for asynchronous operations.
Remove `await` when calling methods on the synchronous interface (e.g., `queue.sync_q.put(item)`), or use the asynchronous interface with `await` (e.g., `await queue.async_q.put(item)`).
No dependency data recorded yet.