aiorwlock


Nameaiorwlock JSON
Version 1.4.0 PyPI version JSON
download
home_pagehttps://github.com/aio-libs/aiorwlock
SummaryRead write lock for asyncio.
upload_time2024-01-20 14:11:47
maintainer
docs_urlNone
authorNikolay Novik
requires_python>=3.8
licenseApache 2
keywords aiorwlock lock asyncio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            aiorwlock
=========
.. image:: https://github.com/aio-libs/aiorwlock/workflows/CI/badge.svg
   :target: https://github.com/aio-libs/aiorwlock/actions?query=workflow%3ACI
.. image:: https://codecov.io/gh/aio-libs/aiorwlock/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/aio-libs/aiorwlock
.. image:: https://badges.gitter.im/Join%20Chat.svg
   :target: https://gitter.im/aio-libs/Lobby
   :alt: Chat on Gitter
.. image:: https://img.shields.io/pypi/dm/aiorwlock
   :target: https://pypistats.org/packages/aiorwlock
   :alt: Downloads count

Read write lock for asyncio_ . A ``RWLock`` maintains a pair of associated
locks, one for read-only operations and one for writing. The read lock may be
held simultaneously by multiple reader tasks, so long as there are
no writers. The write lock is exclusive.

Whether or not a read-write lock will improve performance over the use of
a mutual exclusion lock depends on the frequency that the data is *read*
compared to being *modified*. For example, a collection that is initially
populated with data and thereafter infrequently modified, while being
frequently searched is an ideal candidate for the use of a read-write lock.
However, if updates become frequent then the data spends most of its time
being exclusively locked and there is little, if any increase in concurrency.


Implementation is almost direct port from this patch_.


Example
-------

.. code:: python

   import asyncio
   import aiorwlock


   async def go():
       rwlock = aiorwlock.RWLock()

       # acquire reader lock, multiple coroutines allowed to hold the lock
       async with rwlock.reader_lock:
           print('inside reader lock')
           await asyncio.sleep(0.1)

       # acquire writer lock, only one coroutine can hold the lock
       async with rwlock.writer_lock:
           print('inside writer lock')
           await asyncio.sleep(0.1)


   asyncio.run(go())


Fast path
---------

By default `RWLock` switches context on lock acquiring. That allows to
other waiting tasks get the lock even if task that holds the lock
doesn't contain context switches (`await fut` statements).

The default behavior can be switched off by `fast` argument:
`RWLock(fast=True)`.

Long story short:  lock is safe by  default, but if you  sure you have
context switches (`await`,  `async with`, `async for`  or `yield from`
statements) inside  locked code  you may want  to use  `fast=True` for
minor speedup.


TLA+ Specification
------------------

TLA+ specification of ``aiorwlock`` provided in this repository.


License
-------

``aiorwlock`` is offered under the Apache 2 license.


.. _asyncio: http://docs.python.org/3/library/asyncio.html
.. _patch: http://bugs.python.org/issue8800

Changes
-------

1.4.0 (2024-01-20)
^^^^^^^^^^^^^^^^^^

* Lazily evaluate current loop to allow instantiating lock outside of async functions.
* Support Python 3.11 and 3.12.
* Drop Python 3.7 support.

1.3.0 (2022-01-18)
^^^^^^^^^^^^^^^^^^

* Dropped Python 3.6 support
* Python 3.10 is officially supported
* Drop deprecated `loop` parameter from `RWLock` constructor


1.2.0 (2021-11-09)
^^^^^^^^^^^^^^^^^^

* Fix a bug that makes concurrent writes possible under some (rare) conjunctions (#235)

1.1.0 (2021-09-27)
^^^^^^^^^^^^^^^^^^

* Remove explicit loop usage in `asyncio.sleep()` call, make the library forward
  compatible with Python 3.10

1.0.0 (2020-12-32)
^^^^^^^^^^^^^^^^^^

* Fix a bug with cancelation during acquire #170 (thanks @romasku)

* Deprecate passing explicit `loop` argument to `RWLock` constructor

* Deprecate creation of `RWLock` instance outside of async function context

* Minimal supported version is Python 3.6

* The library works with Python 3.8 and Python 3.9 seamlessly


0.6.0 (2018-12-18)
^^^^^^^^^^^^^^^^^^
* Wake up all readers after writer releases lock #60 (thanks @ranyixu)

* Fixed Python 3.7 compatibility

* Removed old `yield from` syntax

* Minimal supported version is Python 3.5.3

* Removed support for none async context managers

0.5.0 (2017-12-03)
^^^^^^^^^^^^^^^^^^

* Fix corner cases and deadlock when we upgrade lock from write to
  read #39

* Use loop.create_future instead asyncio.Future if possible

0.4.0 (2015-09-20)
^^^^^^^^^^^^^^^^^^

* Support Python 3.5 and `async with` statement

* rename `.reader_lock` -> `.reader`, `.writer_lock` ->
  `.writer`. Backward compatibility is preserved.

0.3.0 (2014-02-11)
^^^^^^^^^^^^^^^^^^

* Add `.locked` property

0.2.0 (2014-02-09)
^^^^^^^^^^^^^^^^^^

* Make `.release()` non-coroutine


0.1.0 (2014-12-22)
^^^^^^^^^^^^^^^^^^

* Initial release

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aio-libs/aiorwlock",
    "name": "aiorwlock",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "aiorwlock,lock,asyncio",
    "author": "Nikolay Novik",
    "author_email": "nickolainovik@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ba/c5/882b4c89d71d6f9c7d0d8dee18d267025e71d4c3241eb3b16ab39105a0d1/aiorwlock-1.4.0.tar.gz",
    "platform": "POSIX",
    "description": "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\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\nChanges\n-------\n\n1.4.0 (2024-01-20)\n^^^^^^^^^^^^^^^^^^\n\n* Lazily evaluate current loop to allow instantiating lock outside of async functions.\n* Support Python 3.11 and 3.12.\n* Drop Python 3.7 support.\n\n1.3.0 (2022-01-18)\n^^^^^^^^^^^^^^^^^^\n\n* Dropped Python 3.6 support\n* Python 3.10 is officially supported\n* Drop deprecated `loop` parameter from `RWLock` constructor\n\n\n1.2.0 (2021-11-09)\n^^^^^^^^^^^^^^^^^^\n\n* Fix a bug that makes concurrent writes possible under some (rare) conjunctions (#235)\n\n1.1.0 (2021-09-27)\n^^^^^^^^^^^^^^^^^^\n\n* Remove explicit loop usage in `asyncio.sleep()` call, make the library forward\n  compatible with Python 3.10\n\n1.0.0 (2020-12-32)\n^^^^^^^^^^^^^^^^^^\n\n* Fix a bug with cancelation during acquire #170 (thanks @romasku)\n\n* Deprecate passing explicit `loop` argument to `RWLock` constructor\n\n* Deprecate creation of `RWLock` instance outside of async function context\n\n* Minimal supported version is Python 3.6\n\n* The library works with Python 3.8 and Python 3.9 seamlessly\n\n\n0.6.0 (2018-12-18)\n^^^^^^^^^^^^^^^^^^\n* Wake up all readers after writer releases lock #60 (thanks @ranyixu)\n\n* Fixed Python 3.7 compatibility\n\n* Removed old `yield from` syntax\n\n* Minimal supported version is Python 3.5.3\n\n* Removed support for none async context managers\n\n0.5.0 (2017-12-03)\n^^^^^^^^^^^^^^^^^^\n\n* Fix corner cases and deadlock when we upgrade lock from write to\n  read #39\n\n* Use loop.create_future instead asyncio.Future if possible\n\n0.4.0 (2015-09-20)\n^^^^^^^^^^^^^^^^^^\n\n* Support Python 3.5 and `async with` statement\n\n* rename `.reader_lock` -> `.reader`, `.writer_lock` ->\n  `.writer`. Backward compatibility is preserved.\n\n0.3.0 (2014-02-11)\n^^^^^^^^^^^^^^^^^^\n\n* Add `.locked` property\n\n0.2.0 (2014-02-09)\n^^^^^^^^^^^^^^^^^^\n\n* Make `.release()` non-coroutine\n\n\n0.1.0 (2014-12-22)\n^^^^^^^^^^^^^^^^^^\n\n* Initial release\n",
    "bugtrack_url": null,
    "license": "Apache 2",
    "summary": "Read write lock for asyncio.",
    "version": "1.4.0",
    "project_urls": {
        "Download": "https://pypi.python.org/pypi/aiorwlock",
        "Homepage": "https://github.com/aio-libs/aiorwlock",
        "Issues": "https://github.com/aio-libs/aiorwlock/issues",
        "Website": "https://github.com/aio-libs/aiorwlock"
    },
    "split_keywords": [
        "aiorwlock",
        "lock",
        "asyncio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0af88d22bbdb42ccd71716fb6fa8c8e10f05fc0964787a9e0a54b975d8c0fd73",
                "md5": "5f56016297074674f6056db1eb61aadb",
                "sha256": "cc99c42463e9915cff528d79b6eb3d518d74bc0edf9edeb8c64228445fb4714b"
            },
            "downloads": -1,
            "filename": "aiorwlock-1.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5f56016297074674f6056db1eb61aadb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 9987,
            "upload_time": "2024-01-20T14:11:43",
            "upload_time_iso_8601": "2024-01-20T14:11:43.302446Z",
            "url": "https://files.pythonhosted.org/packages/0a/f8/8d22bbdb42ccd71716fb6fa8c8e10f05fc0964787a9e0a54b975d8c0fd73/aiorwlock-1.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bac5882b4c89d71d6f9c7d0d8dee18d267025e71d4c3241eb3b16ab39105a0d1",
                "md5": "669ff2887392cfa393205cea23661c2f",
                "sha256": "4cea5bec4e9d03533a26919299394822a1422aa519bca9dd09178ec490f8d1cc"
            },
            "downloads": -1,
            "filename": "aiorwlock-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "669ff2887392cfa393205cea23661c2f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 13185,
            "upload_time": "2024-01-20T14:11:47",
            "upload_time_iso_8601": "2024-01-20T14:11:47.254155Z",
            "url": "https://files.pythonhosted.org/packages/ba/c5/882b4c89d71d6f9c7d0d8dee18d267025e71d4c3241eb3b16ab39105a0d1/aiorwlock-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-20 14:11:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aio-libs",
    "github_project": "aiorwlock",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "aiorwlock"
}
        
Elapsed time: 0.30524s