Skip to main content

Python PIDFile

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.

Release files for python-pidfile 3.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-pidfile 3.1.1
File Size Uploaded
python-pidfile-3.1.1.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-pidfile 3.1.1
File Interpreter ABI Platform
python_pidfile-3.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / python-pidfile-3.1.1.tar.gz

Download URL python-pidfile-3.1.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a604012f689a82c1cc44510a23ce59c326882fb91c21fb40cbab3e957f79f0cd
BLAKE2b-256 checksum
How to use checksums
db5c55a2de1aa946aed1904472724e07eb66aab566291dfc6443c01ccfd61a61
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / python_pidfile-3.1.1-py3-none-any.whl

Download URL python_pidfile-3.1.1-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5f408504303ae0e7f89f22e2818fa67f5797279b474d263f483f4887c093dd7
BLAKE2b-256 checksum
How to use checksums
9bfc706f96514a30365462baa0173deeb6ebd568dacc0767e76c18feafc97fb7
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.0

3 release files

1.0.3

3 release files

1.0.2

3 release files

1.0.1

2 release files

1.0.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page