Python PIDFile
==============
.. image:: https://github.com/mosquito/python-pidfile/actions/workflows/tests.yml/badge.svg
:target: https://github.com/mosquito/python-pidfile/actions/workflows/tests.yml
:alt: Github Actions
.. image:: https://img.shields.io/pypi/v/python-pidfile.svg
:target: https://pypi.python.org/pypi/python-pidfile/
:alt: Latest Version
.. image:: https://img.shields.io/pypi/wheel/python-pidfile.svg
:target: https://pypi.python.org/pypi/python-pidfile/
:alt: round wheels
.. image:: https://img.shields.io/pypi/pyversions/python-pidfile.svg
:target: https://pypi.python.org/pypi/python-pidfile/
:alt: Python versions
.. image:: https://img.shields.io/pypi/l/python-pidfile.svg
:target: https://pypi.python.org/pypi/python-pidfile/
:alt: License
.. image:: https://coveralls.io/repos/github/CostantinoGrana/python-pidfile/badge.svg?branch=master
:target: https://coveralls.io/github/CostantinoGrana/python-pidfile?branch=master
:alt: Coverage Status
Python context manager for managing pid files. Example usage:
.. code-block:: python
import pidfile
import time
print('Starting process')
try:
with pidfile.PIDFile("/var/run/example.pid"):
print('Process started')
time.sleep(30)
except pidfile.AlreadyRunningError:
print('Already running.')
print('Exiting')
The context manager will take care of verifying the existence of a pid file,
check its pid to see if it's alive, check the command line (which should be `<something>/<python name>`), and
if all the conditions are met, rise a `pidfile.AlreadyRunningError` exception.
`PIDFile()` defaults to `pidfile` for the file name, but it's possible to specify another, e.g. `PIDFile('foobar.pid')`.
Under the hood
--------------
The algorithm of the library is very simple, at startup, a file is created,
and after checking that another instance of the program is not running, the
current process ID is written to it.
The check works as follows:
* If the file does not exist, then the check is passed.
* An identifier is written in the file, it is read and checked that a
process running with such an identifier exists, and has the same command line.
Raw data
{
"_id": null,
"home_page": "https://github.com/mosquito/python-pidfile",
"name": "python-pidfile",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Dmitry Orlov <me@mosquito.su>, Costantino Grana <None>, Lorenzo Baraldi <None>, Michele Cancilla <None>",
"author_email": "me@mosquito.su",
"download_url": "https://files.pythonhosted.org/packages/db/5c/55a2de1aa946aed1904472724e07eb66aab566291dfc6443c01ccfd61a61/python-pidfile-3.1.1.tar.gz",
"platform": "unix",
"description": "Python PIDFile\n==============\n\n.. image:: https://github.com/mosquito/python-pidfile/actions/workflows/tests.yml/badge.svg\n :target: https://github.com/mosquito/python-pidfile/actions/workflows/tests.yml\n :alt: Github Actions\n\n.. image:: https://img.shields.io/pypi/v/python-pidfile.svg\n :target: https://pypi.python.org/pypi/python-pidfile/\n :alt: Latest Version\n\n.. image:: https://img.shields.io/pypi/wheel/python-pidfile.svg\n :target: https://pypi.python.org/pypi/python-pidfile/\n :alt: round wheels\n\n.. image:: https://img.shields.io/pypi/pyversions/python-pidfile.svg\n :target: https://pypi.python.org/pypi/python-pidfile/\n :alt: Python versions\n\n.. image:: https://img.shields.io/pypi/l/python-pidfile.svg\n :target: https://pypi.python.org/pypi/python-pidfile/\n :alt: License\n\n.. image:: https://coveralls.io/repos/github/CostantinoGrana/python-pidfile/badge.svg?branch=master\n :target: https://coveralls.io/github/CostantinoGrana/python-pidfile?branch=master\n :alt: Coverage Status\n\n\nPython context manager for managing pid files. Example usage:\n\n.. code-block:: python\n\n import pidfile\n import time\n\n print('Starting process')\n try:\n with pidfile.PIDFile(\"/var/run/example.pid\"):\n print('Process started')\n time.sleep(30)\n except pidfile.AlreadyRunningError:\n print('Already running.')\n\n print('Exiting')\n\nThe context manager will take care of verifying the existence of a pid file,\ncheck its pid to see if it's alive, check the command line (which should be `<something>/<python name>`), and\nif all the conditions are met, rise a `pidfile.AlreadyRunningError` exception.\n\n`PIDFile()` defaults to `pidfile` for the file name, but it's possible to specify another, e.g. `PIDFile('foobar.pid')`.\n\n\nUnder the hood\n--------------\n\nThe algorithm of the library is very simple, at startup, a file is created,\nand after checking that another instance of the program is not running, the\ncurrent process ID is written to it.\n\nThe check works as follows:\n\n* If the file does not exist, then the check is passed.\n* An identifier is written in the file, it is read and checked that a\n process running with such an identifier exists, and has the same command line.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "PIDFile context manager.",
"version": "3.1.1",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9bfc706f96514a30365462baa0173deeb6ebd568dacc0767e76c18feafc97fb7",
"md5": "dd65f5764a0e6c82bd32f972414aa8dd",
"sha256": "c5f408504303ae0e7f89f22e2818fa67f5797279b474d263f483f4887c093dd7"
},
"downloads": -1,
"filename": "python_pidfile-3.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dd65f5764a0e6c82bd32f972414aa8dd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4301,
"upload_time": "2023-03-24T13:32:48",
"upload_time_iso_8601": "2023-03-24T13:32:48.659369Z",
"url": "https://files.pythonhosted.org/packages/9b/fc/706f96514a30365462baa0173deeb6ebd568dacc0767e76c18feafc97fb7/python_pidfile-3.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "db5c55a2de1aa946aed1904472724e07eb66aab566291dfc6443c01ccfd61a61",
"md5": "487d615f77d81ed2feea52d9ad18f59e",
"sha256": "a604012f689a82c1cc44510a23ce59c326882fb91c21fb40cbab3e957f79f0cd"
},
"downloads": -1,
"filename": "python-pidfile-3.1.1.tar.gz",
"has_sig": false,
"md5_digest": "487d615f77d81ed2feea52d9ad18f59e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4501,
"upload_time": "2023-03-24T13:32:49",
"upload_time_iso_8601": "2023-03-24T13:32:49.929872Z",
"url": "https://files.pythonhosted.org/packages/db/5c/55a2de1aa946aed1904472724e07eb66aab566291dfc6443c01ccfd61a61/python-pidfile-3.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-24 13:32:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "mosquito",
"github_project": "python-pidfile",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "python-pidfile"
}