DaemonContext
Context manager daemonizing the process.
Attributes
| Attribute | Type | Description |
|---|---|---|
| workdir | string = DAEMON_WORKDIR | The directory path to change into when the daemon starts, defaulting to DAEMON_WORKDIR if not specified. |
| umask | integer = null | The file mode creation mask to set for the daemon process, provided as an integer or a numeric string. |
| fake | boolean = null | A flag that, when set to True, prevents the process from detaching and closing standard file descriptors for debugging purposes. |
| after_chdir | callable = null | A callback function to be executed immediately after the process changes to the working directory. |
| after_forkers | boolean = True | A flag determining whether to run multiprocessing after-fork registry functions during the daemonization process. |
| stdfds | tuple = (sys.stdin, sys.stdout, sys.stderr) | A tuple containing the standard input, output, and error file objects to be redirected to /dev/null. |
Constructor
Signature
def DaemonContext(
pidfile: Any = None,
workdir: str = None,
umask: int|str = None,
fake: bool = False,
after_chdir: callable = None,
after_forkers: bool = True,
**kwargs: dict
)
Parameters
| Name | Type | Description |
|---|---|---|
| pidfile | Any = None | Path to the PID file for the daemon process. |
| workdir | str = None | The working directory to change to after daemonizing. |
| umask | `int | str` = None |
| fake | bool = False | If true, prevents the actual detachment and forking of the process. |
| after_chdir | callable = None | A callback function to execute after changing the working directory. |
| after_forkers | bool = True | Whether to run multiprocessing after-fork handlers. |
| **kwargs | dict | Additional keyword arguments. |
Methods
redirect_to_null()
@classmethod
def redirect_to_null(
fd: int
) - > null
Redirects a specific file descriptor to the system null device to suppress input or output.
Parameters
| Name | Type | Description |
|---|---|---|
| fd | int | The file descriptor to be redirected to /dev/null. |
Returns
| Type | Description |
|---|---|
null |
open()
@classmethod
def open() - > null
Initializes the daemon environment by detaching the process, changing the working directory, setting the umask, and redirecting standard streams.
Returns
| Type | Description |
|---|---|
null |
close()
@classmethod
def close(
*args: any
) - > null
Closes the daemon context and updates the internal state to indicate the context is no longer active.
Parameters
| Name | Type | Description |
|---|---|---|
| *args | any | Variable arguments typically passed by the context manager exit protocol. |
Returns
| Type | Description |
|---|---|
null |