{"id":13725047,"url":"https://github.com/aio-libs/aiorwlock","last_synced_at":"2025-05-07T19:32:31.784Z","repository":{"id":24893498,"uuid":"28309794","full_name":"aio-libs/aiorwlock","owner":"aio-libs","description":"Read/Write Lock - synchronization primitive for asyncio","archived":false,"fork":false,"pushed_at":"2024-05-20T10:50:07.000Z","size":327,"stargazers_count":135,"open_issues_count":3,"forks_count":14,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-05-21T03:15:23.249Z","etag":null,"topics":["asyncio","concurrency","hacktoberfest","lock","mypy","rwlock"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","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":"2014-12-21T19:08:30.000Z","updated_at":"2024-06-05T11:58:35.754Z","dependencies_parsed_at":"2023-10-11T12:08:26.318Z","dependency_job_id":"7475ce28-d147-4a56-b364-9cef81c2f873","html_url":"https://github.com/aio-libs/aiorwlock","commit_stats":{"total_commits":476,"total_committers":16,"mean_commits":29.75,"dds":0.6596638655462185,"last_synced_commit":"2df35fef70c017960410199ff1fa781938fe70ee"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiorwlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiorwlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiorwlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiorwlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aio-libs","download_url":"https://codeload.github.com/aio-libs/aiorwlock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224645183,"owners_count":17346091,"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":["asyncio","concurrency","hacktoberfest","lock","mypy","rwlock"],"created_at":"2024-08-03T01:02:10.840Z","updated_at":"2025-05-07T19:32:31.779Z","avatar_url":"https://github.com/aio-libs.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"aiorwlock\n=========\n.. image:: https://github.com/aio-libs/aiorwlock/workflows/CI/badge.svg\n   :target: https://github.com/aio-libs/aiorwlock/actions?query=workflow%3ACI\n.. image:: https://codecov.io/gh/aio-libs/aiorwlock/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/aio-libs/aiorwlock\n.. image:: https://badges.gitter.im/Join%20Chat.svg\n   :target: https://gitter.im/aio-libs/Lobby\n   :alt: Chat on Gitter\n.. image:: https://img.shields.io/pypi/dm/aiorwlock\n   :target: https://pypistats.org/packages/aiorwlock\n   :alt: Downloads count\n\nRead write lock for asyncio_ . A ``RWLock`` maintains a pair of associated\nlocks, one for read-only operations and one for writing. The read lock may be\nheld simultaneously by multiple reader tasks, so long as there are\nno writers. The write lock is exclusive.\n\nWhether or not a read-write lock will improve performance over the use of\na mutual exclusion lock depends on the frequency that the data is *read*\ncompared to being *modified*. For example, a collection that is initially\npopulated with data and thereafter infrequently modified, while being\nfrequently searched is an ideal candidate for the use of a read-write lock.\nHowever, if updates become frequent then the data spends most of its time\nbeing exclusively locked and there is little, if any increase in concurrency.\n\n**Note:** a task that *acquires* the lock should be used for *releasing* it.\nLocking from one task and releasing from another one generates ``RuntimeError``.\n\n\nImplementation is almost direct port from this patch_.\n\n\nExample\n-------\n\n.. code:: python\n\n   import asyncio\n   import aiorwlock\n\n\n   async def go():\n       rwlock = aiorwlock.RWLock()\n\n       # acquire reader lock, multiple coroutines allowed to hold the lock\n       async with rwlock.reader_lock:\n           print('inside reader lock')\n           await asyncio.sleep(0.1)\n\n       # acquire writer lock, only one coroutine can hold the lock\n       async with rwlock.writer_lock:\n           print('inside writer lock')\n           await asyncio.sleep(0.1)\n\n\n   asyncio.run(go())\n\n\nFast path\n---------\n\nBy default `RWLock` switches context on lock acquiring. That allows to\nother waiting tasks get the lock even if task that holds the lock\ndoesn't contain context switches (`await fut` statements).\n\nThe default behavior can be switched off by `fast` argument:\n`RWLock(fast=True)`.\n\nLong story short:  lock is safe by  default, but if you  sure you have\ncontext switches (`await`,  `async with`, `async for`  or `yield from`\nstatements) inside  locked code  you may want  to use  `fast=True` for\nminor speedup.\n\n\nTLA+ Specification\n------------------\n\nTLA+ specification of ``aiorwlock`` provided in this repository.\n\n\nLicense\n-------\n\n``aiorwlock`` is offered under the Apache 2 license.\n\n\n.. _asyncio: http://docs.python.org/3/library/asyncio.html\n.. _patch: http://bugs.python.org/issue8800\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faiorwlock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faio-libs%2Faiorwlock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faiorwlock/lists"}