Skip to main content

A simple library for pidfiles support.

Project description

The JustPidFile libraray is a very simple, yet functional, pid file implementation.

This way the first process accessing the pid file, is able to write there its PID (Process ID). The next one will check the file, the pid inside, and will check if the process with the PID exists. If it exists, then an exception is thrown.

If the pid file doesn’t exist, or contains garbage data, or an integer with a PID of a not running process, then the directory can be “locked”.

“Locking” a directory is done by creating a “.pid” file in the directory with the locking process ID inside.

Gotchas

Locking a directory with a simple file works as long as everybody uses the same mechanism. There is nothing that forbids any other process to change files in the “locked” directory. The purpose of this library is to avoid having two processes writing to the same files at the same time.

Example

Lock a directory using the simple functional API

import justpid as jp
directory = "abc"

try:
    jp.lock(directory)
    # some logic
    jp.unlock(directory)
except jp.LockException:
    print("Cannot lock a directory")

Use a context manager to automatically unlock the directory at the end

import justpid as jp

with jp.Lock(directory):
    # do something here
    # the directory is exlusively locked
# and here is unlocked

Implementation Details

There are some hardcoded things like:

  • The pid file is in side the locked directory and is named .pid

  • The main api is made of functions.

  • There is also a context manager, just to make life a little bit simpler.

Do You Need this?

Maybe? Who knows. I need.

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

justpid-1.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

justpid-1.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file justpid-1.1.0.tar.gz.

File metadata

  • Download URL: justpid-1.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.12

File hashes

Hashes for justpid-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d617594f273453b71eda3f40cfc4816ae62de68e79155875cbfcd210291ee9a9
MD5 1a1fb1896f4217177accd182132c4674
BLAKE2b-256 c64d9c74e601501874f6eb4ae14bc24b17c3ad32672ae8dd15804c2d69700867

See more details on using hashes here.

File details

Details for the file justpid-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: justpid-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.12

File hashes

Hashes for justpid-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5d512aa03b6b3f5a50a8ed40dec97bdcd6f34e1db1c832e1d4ca2c04ec40358
MD5 1804066d545f4888751896fa873c67b8
BLAKE2b-256 de1aac3c289e34d21dab5fa0c543d3287a2e134c3d4165f3a65c95251d5d2873

See more details on using hashes here.

Supported by

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