{"id":13478221,"url":"https://github.com/aio-libs/aiojobs","last_synced_at":"2025-03-27T07:30:53.131Z","repository":{"id":22305472,"uuid":"95887977","full_name":"aio-libs/aiojobs","owner":"aio-libs","description":"Jobs scheduler for managing background task (asyncio)","archived":false,"fork":false,"pushed_at":"2025-03-25T19:31:32.000Z","size":655,"stargazers_count":874,"open_issues_count":8,"forks_count":71,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-25T20:29:06.982Z","etag":null,"topics":["aiohttp","asyncio","jobs"],"latest_commit_sha":null,"homepage":"https://aiojobs.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aio-libs.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-30T12:50:11.000Z","updated_at":"2025-03-25T14:04:57.000Z","dependencies_parsed_at":"2023-02-19T12:16:18.075Z","dependency_job_id":"42a8a40d-eb6c-477d-9c07-c6b48e454ccb","html_url":"https://github.com/aio-libs/aiojobs","commit_stats":{"total_commits":406,"total_committers":26,"mean_commits":"15.615384615384615","dds":0.7266009852216748,"last_synced_commit":"492252bbc18790d716ae00375c080f60af9b9aee"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiojobs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiojobs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiojobs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiojobs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aio-libs","download_url":"https://codeload.github.com/aio-libs/aiojobs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245802272,"owners_count":20674625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aiohttp","asyncio","jobs"],"created_at":"2024-07-31T16:01:54.171Z","updated_at":"2025-03-27T07:30:52.641Z","avatar_url":"https://github.com/aio-libs.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"=======\naiojobs\n=======\n.. image:: https://travis-ci.org/aio-libs/aiojobs.svg?branch=master\n    :target: https://travis-ci.org/aio-libs/aiojobs\n.. image:: https://codecov.io/gh/aio-libs/aiojobs/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/aio-libs/aiojobs\n.. image:: https://img.shields.io/pypi/v/aiojobs.svg\n    :target: https://pypi.python.org/pypi/aiojobs\n.. image:: https://readthedocs.org/projects/aiojobs/badge/?version=latest\n    :target: http://aiojobs.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n.. image:: https://badges.gitter.im/Join%20Chat.svg\n    :target: https://gitter.im/aio-libs/Lobby\n    :alt: Chat on Gitter\n\nJob scheduler for managing background tasks (asyncio)\n\n\nThe library gives a controlled way for scheduling background tasks for\nasyncio applications.\n\nInstallation\n============\n\n.. code-block:: bash\n\n   $ pip3 install aiojobs\n\nUsage example\n=============\n\n.. code-block:: python\n\n   import asyncio\n   import aiojobs\n\n   async def coro(timeout):\n       await asyncio.sleep(timeout)\n\n   async def main():\n       async with aiojobs.Scheduler() as scheduler:\n           for i in range(100):\n               # spawn jobs\n               await scheduler.spawn(coro(i/10))\n\n           await asyncio.sleep(5.0)\n           # not all scheduled jobs are finished at the moment\n       # Exit from context will gracefully wait on tasks before closing\n       # any remaining spawned jobs\n\n   asyncio.run(main())\n\nShielding tasks with a scheduler\n================================\n\nIt is typically recommended to use ``asyncio.shield`` to protect tasks\nfrom cancellation. However, the inner shielded tasks can't be tracked and\nare therefore at risk of being cancelled during application shutdown.\n\nTo resolve this issue aiojobs includes a ``aiojobs.Scheduler.shield``\nmethod to shield tasks while also keeping track of them in the scheduler.\nIn combination with the ``aiojobs.Scheduler.wait_and_close`` method,\nthis allows shielded tasks the required time to complete successfully\nduring application shutdown.\n\nFor example:\n\n.. code-block:: python\n\n   import asyncio\n   import aiojobs\n   from contextlib import suppress\n\n   async def important():\n       print(\"START\")\n       await asyncio.sleep(5)\n       print(\"DONE\")\n\n   async def run_something(scheduler):\n       # If we use asyncio.shield() here, then the task doesn't complete and DONE is never printed.\n       await scheduler.shield(important())\n\n   async def main():\n       async with aiojobs.Scheduler() as scheduler:\n           t = asyncio.create_task(run_something(scheduler))\n           await asyncio.sleep(0.1)\n           t.cancel()\n           with suppress(asyncio.CancelledError):\n               await t\n\n   asyncio.run(main())\n\n\nIntegration with aiohttp.web\n============================\n\n.. code-block:: python\n\n   from aiohttp import web\n   from aiojobs.aiohttp import setup, spawn\n\n   async def handler(request):\n       await spawn(request, coro())\n       return web.Response()\n\n   app = web.Application()\n   app.router.add_get('/', handler)\n   setup(app)\n\nor just\n\n.. code-block:: python\n\n   from aiojobs.aiohttp import atomic\n\n   @atomic\n   async def handler(request):\n       return web.Response()\n\nFor more information read documentation: https://aiojobs.readthedocs.io\n\nCommunication channels\n======================\n\n*aio-libs* google group: https://groups.google.com/forum/#!forum/aio-libs\n\nFeel free to post your questions and ideas here.\n\n*Gitter Chat* https://gitter.im/aio-libs/Lobby\n\nWe support `Stack Overflow \u003chttps://stackoverflow.com\u003e`_.\nPlease add *python-asyncio* or *aiohttp* tag to your question there.\n\n\nAuthor and License\n==================\n\nThe ``aiojobs`` package is written by Andrew Svetlov.\n\nIt's *Apache 2* licensed and freely available.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faiojobs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faio-libs%2Faiojobs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faiojobs/lists"}