METADATA 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. Metadata-Version: 2.4
  2. Name: portalocker
  3. Version: 3.2.0
  4. Summary: Wraps the portalocker recipe for easy usage
  5. Author-email: Rick van Hattem <wolph@wol.ph>
  6. License-Expression: BSD-3-Clause
  7. Project-URL: bugs, https://github.com/wolph/portalocker/issues
  8. Project-URL: documentation, https://portalocker.readthedocs.io/en/latest/
  9. Project-URL: repository, https://github.com/wolph/portalocker/
  10. Keywords: locking,locks,with,statement,windows,linux,unix
  11. Platform: any
  12. Classifier: Development Status :: 5 - Production/Stable
  13. Classifier: Development Status :: 6 - Mature
  14. Classifier: Intended Audience :: Developers
  15. Classifier: Natural Language :: English
  16. Classifier: Operating System :: MacOS :: MacOS X
  17. Classifier: Operating System :: MacOS
  18. Classifier: Operating System :: Microsoft :: MS-DOS
  19. Classifier: Operating System :: Microsoft :: Windows
  20. Classifier: Operating System :: Microsoft
  21. Classifier: Operating System :: POSIX :: BSD :: FreeBSD
  22. Classifier: Operating System :: POSIX :: BSD
  23. Classifier: Operating System :: POSIX :: Linux
  24. Classifier: Operating System :: POSIX :: SunOS/Solaris
  25. Classifier: Operating System :: POSIX
  26. Classifier: Operating System :: Unix
  27. Classifier: Programming Language :: Python :: 3 :: Only
  28. Classifier: Programming Language :: Python :: 3
  29. Classifier: Programming Language :: Python :: 3.9
  30. Classifier: Programming Language :: Python :: 3.10
  31. Classifier: Programming Language :: Python :: 3.11
  32. Classifier: Programming Language :: Python :: 3.12
  33. Classifier: Programming Language :: Python :: 3.13
  34. Classifier: Programming Language :: Python :: Implementation :: CPython
  35. Classifier: Programming Language :: Python :: Implementation :: IronPython
  36. Classifier: Programming Language :: Python :: Implementation :: PyPy
  37. Classifier: Programming Language :: Python :: Implementation
  38. Classifier: Programming Language :: Python
  39. Classifier: Topic :: Education :: Testing
  40. Classifier: Topic :: Office/Business
  41. Classifier: Topic :: Other/Nonlisted Topic
  42. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  43. Classifier: Topic :: Software Development :: Libraries
  44. Classifier: Topic :: System :: Monitoring
  45. Classifier: Typing :: Typed
  46. Requires-Python: >=3.9
  47. Description-Content-Type: text/x-rst
  48. License-File: LICENSE
  49. Requires-Dist: pywin32>=226; platform_system == "Windows"
  50. Provides-Extra: docs
  51. Requires-Dist: portalocker[tests]; extra == "docs"
  52. Provides-Extra: tests
  53. Requires-Dist: coverage-conditional-plugin>=0.9.0; extra == "tests"
  54. Requires-Dist: portalocker[redis]; extra == "tests"
  55. Requires-Dist: pytest-cov>=2.8.1; extra == "tests"
  56. Requires-Dist: pytest-mypy>=0.8.0; extra == "tests"
  57. Requires-Dist: pytest-rerunfailures>=15.0; extra == "tests"
  58. Requires-Dist: pytest-timeout>=2.1.0; extra == "tests"
  59. Requires-Dist: pytest>=5.4.1; extra == "tests"
  60. Requires-Dist: sphinx>=6.0.0; extra == "tests"
  61. Requires-Dist: types-pywin32>=310.0.0.20250429; extra == "tests"
  62. Requires-Dist: types-redis; extra == "tests"
  63. Provides-Extra: redis
  64. Requires-Dist: redis; extra == "redis"
  65. Dynamic: license-file
  66. ############################################
  67. portalocker - Cross-platform locking library
  68. ############################################
  69. .. image:: https://github.com/WoLpH/portalocker/actions/workflows/python-package.yml/badge.svg?branch=master
  70. :alt: Linux Test Status
  71. :target: https://github.com/WoLpH/portalocker/actions/
  72. .. image:: https://ci.appveyor.com/api/projects/status/mgqry98hgpy4prhh?svg=true
  73. :alt: Windows Tests Status
  74. :target: https://ci.appveyor.com/project/WoLpH/portalocker
  75. .. image:: https://coveralls.io/repos/WoLpH/portalocker/badge.svg?branch=master
  76. :alt: Coverage Status
  77. :target: https://coveralls.io/r/WoLpH/portalocker?branch=master
  78. Overview
  79. --------
  80. Portalocker is a library to provide an easy API to file locking.
  81. An important detail to note is that on Linux and Unix systems the locks are
  82. advisory by default. By specifying the `-o mand` option to the mount command it
  83. is possible to enable mandatory file locking on Linux. This is generally not
  84. recommended however. For more information about the subject:
  85. - https://en.wikipedia.org/wiki/File_locking
  86. - http://stackoverflow.com/questions/39292051/portalocker-does-not-seem-to-lock
  87. - https://stackoverflow.com/questions/12062466/mandatory-file-lock-on-linux
  88. The module is currently maintained by Rick van Hattem <Wolph@wol.ph>.
  89. The project resides at https://github.com/WoLpH/portalocker . Bugs and feature
  90. requests can be submitted there. Patches are also very welcome.
  91. Security contact information
  92. ------------------------------------------------------------------------------
  93. To report a security vulnerability, please use the
  94. `Tidelift security contact <https://tidelift.com/security>`_.
  95. Tidelift will coordinate the fix and disclosure.
  96. Redis Locks
  97. -----------
  98. This library now features a lock based on Redis which allows for locks across
  99. multiple threads, processes and even distributed locks across multiple
  100. computers.
  101. It is an extremely reliable Redis lock that is based on pubsub.
  102. As opposed to most Redis locking systems based on key/value pairs,
  103. this locking method is based on the pubsub system. The big advantage is
  104. that if the connection gets killed due to network issues, crashing
  105. processes or otherwise, it will still immediately unlock instead of
  106. waiting for a lock timeout.
  107. First make sure you have everything installed correctly:
  108. ::
  109. pip install "portalocker[redis]"
  110. Usage is really easy:
  111. ::
  112. import portalocker
  113. lock = portalocker.RedisLock('some_lock_channel_name')
  114. with lock:
  115. print('do something here')
  116. The API is essentially identical to the other ``Lock`` classes so in addition
  117. to the ``with`` statement you can also use ``lock.acquire(...)``.
  118. Python 2
  119. --------
  120. Python 2 was supported in versions before Portalocker 2.0. If you are still
  121. using
  122. Python 2,
  123. you can run this to install:
  124. ::
  125. pip install "portalocker<2"
  126. Tips
  127. ----
  128. On some networked filesystems it might be needed to force a `os.fsync()` before
  129. closing the file so it's actually written before another client reads the file.
  130. Effectively this comes down to:
  131. ::
  132. with portalocker.Lock('some_file', 'rb+', timeout=60) as fh:
  133. # do what you need to do
  134. ...
  135. # flush and sync to filesystem
  136. fh.flush()
  137. os.fsync(fh.fileno())
  138. Links
  139. -----
  140. * Documentation
  141. - http://portalocker.readthedocs.org/en/latest/
  142. * Source
  143. - https://github.com/WoLpH/portalocker
  144. * Bug reports
  145. - https://github.com/WoLpH/portalocker/issues
  146. * Package homepage
  147. - https://pypi.python.org/pypi/portalocker
  148. * My blog
  149. - http://w.wol.ph/
  150. Examples
  151. --------
  152. To make sure your cache generation scripts don't race, use the `Lock` class:
  153. >>> import portalocker
  154. >>> with portalocker.Lock('somefile', timeout=1) as fh:
  155. ... print('writing some stuff to my cache...', file=fh)
  156. To customize the opening and locking a manual approach is also possible:
  157. >>> import portalocker
  158. >>> file = open('somefile', 'r+')
  159. >>> portalocker.lock(file, portalocker.LockFlags.EXCLUSIVE)
  160. >>> file.seek(12)
  161. >>> file.write('foo')
  162. >>> file.close()
  163. Explicitly unlocking is not needed in most cases but omitting it has been known
  164. to cause issues:
  165. https://github.com/AzureAD/microsoft-authentication-extensions-for-python/issues/42#issuecomment-601108266
  166. If needed, it can be done through:
  167. >>> portalocker.unlock(file)
  168. Do note that your data might still be in a buffer so it is possible that your
  169. data is not available until you `flush()` or `close()`.
  170. To create a cross platform bounded semaphore across multiple processes you can
  171. use the `BoundedSemaphore` class which functions somewhat similar to
  172. `threading.BoundedSemaphore`:
  173. >>> import portalocker
  174. >>> n = 2
  175. >>> timeout = 0.1
  176. >>> semaphore_a = portalocker.BoundedSemaphore(n, timeout=timeout)
  177. >>> semaphore_b = portalocker.BoundedSemaphore(n, timeout=timeout)
  178. >>> semaphore_c = portalocker.BoundedSemaphore(n, timeout=timeout)
  179. >>> semaphore_a.acquire()
  180. <portalocker.utils.Lock object at ...>
  181. >>> semaphore_b.acquire()
  182. <portalocker.utils.Lock object at ...>
  183. >>> semaphore_c.acquire()
  184. Traceback (most recent call last):
  185. ...
  186. portalocker.exceptions.AlreadyLocked
  187. More examples can be found in the
  188. `tests <http://portalocker.readthedocs.io/en/latest/_modules/tests/tests.html>`_.
  189. Versioning
  190. ----------
  191. This library follows `Semantic Versioning <http://semver.org/>`_.
  192. Changelog
  193. ---------
  194. Every release has a ``git tag`` with a commit message for the tag
  195. explaining what was added and/or changed. The list of tags/releases
  196. including the commit messages can be found here:
  197. https://github.com/WoLpH/portalocker/releases
  198. License
  199. -------
  200. See the `LICENSE <https://github.com/WoLpH/portalocker/blob/develop/LICENSE>`_ file.