{"id":13781764,"url":"https://github.com/harlowja/fasteners","last_synced_at":"2026-02-22T05:32:48.710Z","repository":{"id":28455201,"uuid":"31970793","full_name":"harlowja/fasteners","owner":"harlowja","description":"A python package that provides useful locks.","archived":false,"fork":false,"pushed_at":"2025-03-11T06:19:54.000Z","size":1709,"stargazers_count":255,"open_issues_count":23,"forks_count":45,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-04T18:50:05.211Z","etag":null,"topics":[],"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/harlowja.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-03-10T17:14:45.000Z","updated_at":"2025-03-23T04:52:40.000Z","dependencies_parsed_at":"2024-01-16T00:36:27.132Z","dependency_job_id":"a43bf133-ce9a-4271-9a8f-d21213d3e59f","html_url":"https://github.com/harlowja/fasteners","commit_stats":{"total_commits":189,"total_committers":22,"mean_commits":8.590909090909092,"dds":0.6772486772486772,"last_synced_commit":"efc35831d378a938ae852c94aaf233112e041669"},"previous_names":["harlowja/sharedlock"],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harlowja%2Ffasteners","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harlowja%2Ffasteners/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harlowja%2Ffasteners/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harlowja%2Ffasteners/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harlowja","download_url":"https://codeload.github.com/harlowja/fasteners/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253584492,"owners_count":21931547,"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":[],"created_at":"2024-08-03T18:01:29.073Z","updated_at":"2025-10-20T16:12:29.143Z","avatar_url":"https://github.com/harlowja.png","language":"Python","funding_links":[],"categories":["Python decorator in the wild"],"sub_categories":[],"readme":"Fasteners\n=========\n\n[![Documentation status](https://readthedocs.org/projects/fasteners/badge/?version=latest)](https://readthedocs.org/projects/fasteners/?badge=latest)\n[![Latest version](https://img.shields.io/pypi/v/fasteners.svg)](https://pypi.python.org/pypi/fasteners/)\n\nCross-platform locks for threads and processes.\n\n🔩 Install\n----------\n\n```\npip install fasteners\n```\n\n🔩 Usage\n--------\nLock for processes has the same API as the \n[threading.Lock](https://docs.python.org/3/library/threading.html#threading.Lock)\nfor threads:\n```python\nimport fasteners\nimport threading\n\nlock = threading.Lock()                                 # for threads\nlock = fasteners.InterProcessLock('path/to/lock.file')  # for processes\n\nwith lock:\n    ... # exclusive access\n\n# or alternatively    \n\nlock.acquire()\n... # exclusive access\nlock.release()\n```\n\nReader Writer lock has a similar API, which is the same for threads or processes:\n\n```python\nimport fasteners\n\nrw_lock = fasteners.ReaderWriterLock()                                 # for threads\nrw_lock = fasteners.InterProcessReaderWriterLock('path/to/lock.file')  # for processes\n\nwith rw_lock.write_lock():\n    ... # write access\n\nwith rw_lock.read_lock():\n    ... # read access\n\n# or alternatively\n\nrw_lock.acquire_read_lock()\n... # read access\nrw_lock.release_read_lock()\n\nrw_lock.acquire_write_lock()\n... # write access\nrw_lock.release_write_lock()\n```\n\n🔩 Overview\n-----------\n\nPython standard library provides a lock for threads (both a reentrant one, and a\nnon-reentrant one, see below). Fasteners extends this, and provides a lock for\nprocesses, as well as Reader Writer locks for both threads and processes.\nDefinitions of terms used in this overview can be found in the\n[glossary](https://fasteners.readthedocs.io/en/latest/guide/glossary/).\n\nThe specifics of the locks are as follows:\n\n### Process locks\n\nThe `fasteners.InterProcessLock` uses [fcntl](https://man7.org/linux/man-pages/man2/fcntl.2.html) on Unix-like systems and \nmsvc [_locking](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/locking?view=msvc-160) on Windows. \nAs a result, if used cross-platform it guarantees an intersection of their features:\n\n| lock | reentrant | mandatory |\n|------|-----------|-----------|\n| fcntl                        | ✘ | ✘ |\n| _locking                     | ✔ | ✔ |\n| fasteners.InterProcessLock   | ✘ | ✘ |\n\n\nThe `fasteners.InterProcessReaderWriterLock` also uses fcntl on Unix-like systems and \n[LockFileEx](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-lockfileex) on Windows. Their \nfeatures are as follows:\n\n| lock | reentrant | mandatory | upgradable | preference | \n|------|-----------|-----------|------------|------------|\n| fcntl                                    | ✘ | ✘ | ✔ | reader |\n| LockFileEx                               | ✔ | ✔ | ✘ | reader |\n| fasteners.InterProcessReaderWriterLock   | ✘ | ✘ | ✘ | reader |\n\n\n### Thread locks\n\nFasteners does not provide a simple thread lock, but for the sake of comparison note that the `threading` module\nprovides both a reentrant and non-reentrant locks:\n\n| lock | reentrant | mandatory |\n|------|-----------|-----------|\n| threading.Lock  | ✘ | ✘ |\n| threading.RLock | ✔ | ✘ |\n\n\nThe `fasteners.ReaderWriterLock` at the moment is as follows:\n\n| lock | reentrant | mandatory | upgradable | preference | \n|------|-----------|-----------|-------------|------------|\n| fasteners.ReaderWriterLock | ✔ | ✘ | ✘ | writer |\n\nIf your threads are created by some other means than the standard library `threading`\nmodule (for example `eventlet`), you may need to provide the corresponding thread\nidentification and synchronisation functions to the `ReaderWriterLock`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharlowja%2Ffasteners","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharlowja%2Ffasteners","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharlowja%2Ffasteners/lists"}