Skip to main content

PIDFile context processor. Supported py2 and py3

Project description

Github Actions Latest Version round wheels Python versions License Coverage Status

Python context manager for managing pid files. Example usage:

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-pidfile-3.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

python_pidfile-3.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file python-pidfile-3.1.0.tar.gz.

File metadata

  • Download URL: python-pidfile-3.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/32.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.62.3 importlib-metadata/5.2.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python-pidfile-3.1.0.tar.gz
Algorithm Hash digest
SHA256 e975d943f93db42772eb317c66368dd809ee67a4b05c4fa5602a918a53f55b2b
MD5 7b688ef2299528937f36e59e4005e157
BLAKE2b-256 7bcaeb2a5e5fe40f5e377b917bd4b6e449dafca59be9f2e02010515025ad85e1

See more details on using hashes here.

File details

Details for the file python_pidfile-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_pidfile-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/32.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.62.3 importlib-metadata/5.2.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_pidfile-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c4368889901700f0124453561abeb25591bda57f518344c3000f110c834db85
MD5 dfab9657350bd32c5ad93a4453e033fa
BLAKE2b-256 f44a6e394909ada834d2206306d8a082887bce05e9d6872cf69d30b16060b0c4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page