{ "info": { "author": "Will Breaden Madden", "author_email": "wbm@protonmail.ch", "bugtrack_url": null, "classifiers": [], "description": "lock\n====\n\nThis is a module for enabling file locks. It uses ``fcntl`` to\naccomplish this.\n\nPOSIX operating systems implement advisory file locking. This enables\nconcurrent processes to interact with the same file without conflict,\nprovided they first check for the existence of a lock held by a\ndifferent process. Mandatory file locking can be enabled on POSIX\nsystems by mounting volumes using the ``mount`` ``-o mand`` option and\nmakes the operating system prevent editing of a locked file.\n\nThe ``fcntl`` functionality is implemented in Python by the ``fcntl``\nstandard library module. Using this, a lock can be acquired in a way\nlike the following:\n\n.. code:: python\n\n lock_file = open(\"data.db\", \"a\")\n fcntl.lockf(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB)\n\nIf the file is locked, the following exception is raised:\n\n.. code:: python\n\n BlockingIOError: [Errno 11] Resource temporarily unavailable\n\nWith advisory locking, code should test for the existence of a a lock\nbefore editing a file. It is the responsibility of the code, not the\noperating system, to enforce locking correctly. Information about the\nlocks currently held on a file may be retrieved by passing a bytes\nobject as the third argument to the ``fcntl.fcntl`` function (which\ntakes the place of a pointer to the process ID in the fcntl header). The\nlock information can be accessed in a way like the following:\n\n.. code:: python\n\n lock_data = struct.pack(\"hhllhh\", fcntl.F_WRLCK, 0, 0, 0, 0, 0)\n fcntl.fcntl(lock_file, fcntl.F_GETLK, lock_data)\n\nThis returns ``lock_data`` unchanged if there is no lock on the file.\n\nexamples\n========\n\nThe following code saves a dictionary to a file in a loop using ``lock``\nto lock the file while the save is happening:\n\n.. code:: python\n\n import random\n\n import lock\n\n while True:\n config = {\"a\": 1, \"b\": random.randint(1, 2)}\n lock.save_JSON(\"config.json\", config)\n\nThe following code loads a dictionary from a file in a loop using\n``lock`` to lock the file while the load is happening:\n\n.. code:: python\n\n import lock\n\n while True:\n config = lock.load_JSON(\"config.json\")\n if config: print(config)\n\nThese two pieces of code can be used concurrently.\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/wdbm/lock", "keywords": "", "license": "GPLv3", "maintainer": "", "maintainer_email": "", "name": "lock", "package_url": "https://pypi.org/project/lock/", "platform": "", "project_url": "https://pypi.org/project/lock/", "project_urls": { "Homepage": "https://github.com/wdbm/lock" }, "release_url": "https://pypi.org/project/lock/2018.3.25.2110/", "requires_dist": null, "requires_python": "", "summary": "module for enabling file locks", "version": "2018.3.25.2110" }, "last_serial": 3704331, "releases": { "2018.3.25.2110": [ { "comment_text": "", "digests": { "md5": "435db9197f018956cbdddb58af977858", "sha256": "cc5ac770930493eed7a8cfd0cf2568a125faf112eb8aa6b6149b3e581523d0c7" }, "downloads": -1, "filename": "lock-2018.3.25.2110.tar.gz", "has_sig": false, "md5_digest": "435db9197f018956cbdddb58af977858", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3049, "upload_time": "2018-03-25T21:12:37", "url": "https://files.pythonhosted.org/packages/ea/ee/4c7e9740d397abd62b48bfe82f77f57a8984da4f5ba0a3b64930b44ccd8f/lock-2018.3.25.2110.tar.gz" } ], "2018.3.8.1911": [ { "comment_text": "", "digests": { "md5": "18600d3f1f9611c3bd72f5c2725b83ec", "sha256": "8b599a5165aa0df8b5348dfc091ab45d19a774ec0eb1720f00fffbf57c890922" }, "downloads": -1, "filename": "lock-2018.3.8.1911.tar.gz", "has_sig": false, "md5_digest": "18600d3f1f9611c3bd72f5c2725b83ec", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3050, "upload_time": "2018-03-08T19:47:38", "url": "https://files.pythonhosted.org/packages/4e/c2/bddf8c5efe7a336c5ab0faea5e635e4e50755f2428f0f7b07d4f8aade57e/lock-2018.3.8.1911.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "435db9197f018956cbdddb58af977858", "sha256": "cc5ac770930493eed7a8cfd0cf2568a125faf112eb8aa6b6149b3e581523d0c7" }, "downloads": -1, "filename": "lock-2018.3.25.2110.tar.gz", "has_sig": false, "md5_digest": "435db9197f018956cbdddb58af977858", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3049, "upload_time": "2018-03-25T21:12:37", "url": "https://files.pythonhosted.org/packages/ea/ee/4c7e9740d397abd62b48bfe82f77f57a8984da4f5ba0a3b64930b44ccd8f/lock-2018.3.25.2110.tar.gz" } ] }