Go to the latest version of this document.

# ``twisted`.`application`.`runner`.`_pidfile`.`PIDFile``

class documentation

`class PIDFile: (source)`

Constructor: `PIDFile(filePath)`

Implements interfaces: `twisted.application.runner._pidfile.IPIDFile`

View In Hierarchy

Concrete implementation of `IPIDFile`.

This implementation is presently not supported on non-POSIX platforms. Specifically, calling `PIDFile.isRunning` will raise `NotImplementedError`.

Method | `__enter__` | Enter a context using this PIDFile.
Method | `__exit__` | Exit a context using this PIDFile.
Method | `__init__` | No summary
Method | `isRunning` | Determine whether there is a running process corresponding to the PID in this PID file.
Method | `read` | Read the process ID stored in this PID file.
Method | `remove` | Remove this PID file.
Method | `writeRunningPID` | Store the PID of the current process in this PID file.
Instance Variable | `filePath` | Undocumented
Static Method | `_format` | Format a PID file's content.
Static Method | `_pidIsRunningPOSIX` | POSIX implementation for running process check.
Method | `_write` | Store a PID in this PID file.
Class Variable | `_log` | Undocumented

def __enter__(self) -> `PIDFile`: (source)
from `twisted.application.runner._pidfile.IPIDFile`

Enter a context using this PIDFile.

Writes the PID file with the PID of the running process.

Raises
`AlreadyRunningError` | A process corresponding to the PID in this PID file is already running.

def __exit__(self, excType: `type[BaseException] | None`, excValue: `BaseException | None`, traceback: `TracebackType | None`): (source)
from `twisted.application.runner._pidfile.IPIDFile`

Exit a context using this PIDFile.

Removes the PID file.

def __init__(self, filePath: `FilePath[Any]`): (source)

Parameters
filePath:`FilePath[Any]` | The path to the PID file on disk.

def isRunning(self) -> `bool`: (source)
from `twisted.application.runner._pidfile.IPIDFile`

Determine whether there is a running process corresponding to the PID in this PID file.

Returns
`bool` | True if this PID file contains a PID and a process with that PID is currently running; false otherwise.

Raises
`EnvironmentError` | If this PID file cannot be read.
`InvalidPIDFileError` | If this PID file's content is invalid.
`StalePIDFileError` | If this PID file's content refers to a PID for which there is no corresponding running process.

def read(self) -> `int`: (source)
from `twisted.application.runner._pidfile.IPIDFile`

Read the process ID stored in this PID file.

Returns
`int` | The contained process ID.

Raises
`NoPIDFound` | If this PID file does not exist.
`EnvironmentError` | If this PID file cannot be read.
`ValueError` | If this PID file's content is invalid.

def remove(self): (source)
from `twisted.application.runner._pidfile.IPIDFile`

Remove this PID file.

Raises
`EnvironmentError` | If this PID file cannot be removed.

def writeRunningPID(self): (source)
from `twisted.application.runner._pidfile.IPIDFile`

Store the PID of the current process in this PID file.

Raises
`EnvironmentError` | If this PID file cannot be written.

filePath = (source)

Undocumented

@staticmethod
def _format(pid: `int`) -> `bytes`: (source)

Format a PID file's content.

Parameters
pid:`int` | A process ID.

Returns
`bytes` | Formatted PID file contents.

@staticmethod
def _pidIsRunningPOSIX(pid: `int`) -> `bool`: (source)

POSIX implementation for running process check.

Determine whether there is a running process corresponding to the given PID.

Parameters
pid:`int` | The PID to check.

Returns
`bool` | True if the given PID is currently running; false otherwise.

Raises
`EnvironmentError` | If this PID file cannot be read.
`InvalidPIDFileError` | If this PID file's content is invalid.
`StalePIDFileError` | If this PID file's content refers to a PID for which there is no corresponding running process.

def _write(self, pid: `int`): (source)

Store a PID in this PID file.

Parameters
pid:`int` | A PID to store.

Raises
`EnvironmentError` | If this PID file cannot be written.

_log = (source)

Undocumented