janus


Namejanus JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/aio-libs/janus
SummaryMixed sync-async queue to interoperate between asyncio tasks and classic threads
upload_time2021-12-17 09:00:33
maintainer
docs_urlNone
authorAndrew Svetlov <andrew.svetlov@gmail.com>
requires_python>=3.7
licenseApache 2
keywords janus queue asyncio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            =======
 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 Gitter



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 <https://en.wikipedia.org/wiki/Janus>`_ the queue
object from the library has two faces: synchronous and asynchronous
interface.

Synchronous is fully compatible with `standard queue
<https://docs.python.org/3/library/queue.html>`_, asynchronous one
follows `asyncio queue design
<https://docs.python.org/3/library/asyncio-queue.html>`_.

Usage example (Python 3.7+)
===========================

.. code:: python

    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())


Usage example (Python 3.5 and 3.6)
==================================

.. code:: python

    import asyncio
    import janus

    loop = asyncio.get_event_loop()


    def threaded(sync_q):
        for i in range(100):
            sync_q.put(i)
        sync_q.join()


    async def async_coro(async_q):
        for i in range(100):
            val = await async_q.get()
            assert val == i
            async_q.task_done()


    async def main():
        queue = janus.Queue()
        fut = loop.run_in_executor(None, threaded, queue.sync_q)
        await async_coro(queue.async_q)
        await fut
        queue.close()
        await queue.wait_closed()

    try:
        loop.run_until_complete(main())
    finally:
        loop.close()


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



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aio-libs/janus",
    "name": "janus",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "janus,queue,asyncio",
    "author": "Andrew Svetlov <andrew.svetlov@gmail.com>",
    "author_email": "andrew.svetlov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b8/a8/facab7275d7d3d2032f375843fe46fad1cfa604a108b5a238638d4615bdc/janus-1.0.0.tar.gz",
    "platform": "",
    "description": "=======\n janus\n=======\n.. image:: https://github.com/aio-libs/janus/actions/workflows/ci.yml/badge.svg\n    :target: https://github.com/aio-libs/janus/actions/workflows/ci.yml\n.. image:: https://codecov.io/gh/aio-libs/janus/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/aio-libs/janus\n.. image:: https://img.shields.io/pypi/v/janus.svg\n    :target: https://pypi.python.org/pypi/janus\n.. image:: https://badges.gitter.im/Join%20Chat.svg\n    :target: https://gitter.im/aio-libs/Lobby\n    :alt: Chat on Gitter\n\n\n\nMixed sync-async queue, supposed to be used for communicating between\nclassic synchronous (threaded) code and asynchronous (in terms of\nasyncio_) one.\n\nLike `Janus god <https://en.wikipedia.org/wiki/Janus>`_ the queue\nobject from the library has two faces: synchronous and asynchronous\ninterface.\n\nSynchronous is fully compatible with `standard queue\n<https://docs.python.org/3/library/queue.html>`_, asynchronous one\nfollows `asyncio queue design\n<https://docs.python.org/3/library/asyncio-queue.html>`_.\n\nUsage example (Python 3.7+)\n===========================\n\n.. code:: python\n\n    import asyncio\n    import janus\n\n\n    def threaded(sync_q: janus.SyncQueue[int]) -> None:\n        for i in range(100):\n            sync_q.put(i)\n        sync_q.join()\n\n\n    async def async_coro(async_q: janus.AsyncQueue[int]) -> None:\n        for i in range(100):\n            val = await async_q.get()\n            assert val == i\n            async_q.task_done()\n\n\n    async def main() -> None:\n        queue: janus.Queue[int] = janus.Queue()\n        loop = asyncio.get_running_loop()\n        fut = loop.run_in_executor(None, threaded, queue.sync_q)\n        await async_coro(queue.async_q)\n        await fut\n        queue.close()\n        await queue.wait_closed()\n\n\n    asyncio.run(main())\n\n\nUsage example (Python 3.5 and 3.6)\n==================================\n\n.. code:: python\n\n    import asyncio\n    import janus\n\n    loop = asyncio.get_event_loop()\n\n\n    def threaded(sync_q):\n        for i in range(100):\n            sync_q.put(i)\n        sync_q.join()\n\n\n    async def async_coro(async_q):\n        for i in range(100):\n            val = await async_q.get()\n            assert val == i\n            async_q.task_done()\n\n\n    async def main():\n        queue = janus.Queue()\n        fut = loop.run_in_executor(None, threaded, queue.sync_q)\n        await async_coro(queue.async_q)\n        await fut\n        queue.close()\n        await queue.wait_closed()\n\n    try:\n        loop.run_until_complete(main())\n    finally:\n        loop.close()\n\n\nCommunication channels\n======================\n\nGitHub Discussions: https://github.com/aio-libs/janus/discussions\n\nFeel free to post your questions and ideas here.\n\n*gitter chat* https://gitter.im/aio-libs/Lobby\n\n\nLicense\n=======\n\n``janus`` library is offered under Apache 2 license.\n\nThanks\n======\n\nThe library development is sponsored by DataRobot (https://datarobot.com)\n\n.. _asyncio: https://docs.python.org/3/library/asyncio.html\n\n\n",
    "bugtrack_url": null,
    "license": "Apache 2",
    "summary": "Mixed sync-async queue to interoperate between asyncio tasks and classic threads",
    "version": "1.0.0",
    "split_keywords": [
        "janus",
        "queue",
        "asyncio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "f941de0d6c8564870d79da4320652adb",
                "sha256": "2596ea5482711c1ee3ef2df6c290aaf370a13c55a007826e8f7c32d696d1d00a"
            },
            "downloads": -1,
            "filename": "janus-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f941de0d6c8564870d79da4320652adb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6895,
            "upload_time": "2021-12-17T09:00:32",
            "upload_time_iso_8601": "2021-12-17T09:00:32.868340Z",
            "url": "https://files.pythonhosted.org/packages/c1/84/7bfe436fa6a4943eecb17c2cca9c84215299684575376d664ea6bf294439/janus-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "2d8c0b884c14f18fc5223858eb16461e",
                "sha256": "df976f2cdcfb034b147a2d51edfc34ff6bfb12d4e2643d3ad0e10de058cb1612"
            },
            "downloads": -1,
            "filename": "janus-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2d8c0b884c14f18fc5223858eb16461e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 19043,
            "upload_time": "2021-12-17T09:00:33",
            "upload_time_iso_8601": "2021-12-17T09:00:33.923990Z",
            "url": "https://files.pythonhosted.org/packages/b8/a8/facab7275d7d3d2032f375843fe46fad1cfa604a108b5a238638d4615bdc/janus-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-12-17 09:00:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "aio-libs",
    "github_project": "janus",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "janus"
}
        
Elapsed time: 0.04049s