Skip to main content

PIDFile context manager.

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')
    with pidfile.PIDFile("/var/run/"):
        print('Process started')
except pidfile.AlreadyRunningError:
    print('Already running.')


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(‘’).

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.

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.1.tar.gz (4.5 kB view hashes)

Uploaded source

Built Distribution

python_pidfile-3.1.1-py3-none-any.whl (4.3 kB view hashes)

Uploaded py3

Supported by

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