Skip to content

pidfile

Logic around PID file

Classes:

Functions:

Pidfile

Pidfile(pid_name: str | None = None, pidfile_path: Path | str | None = None)

PID file handler

Constructor function to

Parameters:

  • pid_name

    (str | None, default: None ) –

    PID name

  • pidfile_path

    (Path | str | None, default: None ) –

    PID file path (folder where to store the PID file)

Methods:

  • __repr__

    Method to return a string representation of the class.

  • __str__

    Method to return a string representation of the class.

  • delete

    Method to delete the pidfile.

  • get_abs_path

    Method to return the absolute path of the pidfile.

  • is_existing_file

    Method to check if the pidfile exists.

  • read

    Method to read the pid from the pidfile.

  • write

    Method to write the pid to the pidfile.

__repr__

__repr__() -> str

Method to return a string representation of the class.

Returns:

  • str

    String representation of the class.

__str__

__str__() -> str

Method to return a string representation of the class.

Returns:

  • str

    String representation of the class.

delete

delete() -> bool

Method to delete the pidfile.

Returns:

  • bool

    True if the pidfile was deleted, False otherwise.

get_abs_path

get_abs_path() -> str

Method to return the absolute path of the pidfile.
(simple concatenation between pid_path and pid_filename)

Returns:

  • str

    The absolute path of the pidfile.

is_existing_file

is_existing_file() -> bool

Method to check if the pidfile exists.

Returns:

  • bool

    True if the pidfile exists, False otherwise.

read

read() -> int

Method to read the pid from the pidfile.

Returns:

  • int

    The pid read from the pidfile.

write

write(pid: int | str = 0) -> bool

Method to write the pid to the pidfile.

Parameters:

  • pid

    (int | str, default: 0 ) –

    The pid to write to the pidfile.

Returns:

  • bool

ensure_existing_path

ensure_existing_path(path_: Path) -> None

Function to ensure if a given path exists on the disk
If not, create it and add it to the disk

Parameters:

  • path_

    (Path) –

    Path to be checked

Returns:

  • Nothing

    None

generate_random_pid_name

generate_random_pid_name(length: int = DEFAULT_PID_FILENAME_LENGTH) -> str

Function to generate a default PID file name with a random name

Parameters:

  • length

    (int, default: DEFAULT_PID_FILENAME_LENGTH ) –

    PID name length

Returns:

  • str

    Random PID file name