Skip to main content

DaemonContext

Context manager daemonizing the process.

Attributes

AttributeTypeDescription
workdirstring = DAEMON_WORKDIRThe directory path to change into when the daemon starts, defaulting to DAEMON_WORKDIR if not specified.
umaskinteger = nullThe file mode creation mask to set for the daemon process, provided as an integer or a numeric string.
fakeboolean = nullA flag that, when set to True, prevents the process from detaching and closing standard file descriptors for debugging purposes.
after_chdircallable = nullA callback function to be executed immediately after the process changes to the working directory.
after_forkersboolean = TrueA flag determining whether to run multiprocessing after-fork registry functions during the daemonization process.
stdfdstuple = (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

NameTypeDescription
pidfileAny = NonePath to the PID file for the daemon process.
workdirstr = NoneThe working directory to change to after daemonizing.
umask`intstr` = None
fakebool = FalseIf true, prevents the actual detachment and forking of the process.
after_chdircallable = NoneA callback function to execute after changing the working directory.
after_forkersbool = TrueWhether to run multiprocessing after-fork handlers.
**kwargsdictAdditional 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

NameTypeDescription
fdintThe file descriptor to be redirected to /dev/null.

Returns

TypeDescription
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

TypeDescription
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

NameTypeDescription
*argsanyVariable arguments typically passed by the context manager exit protocol.

Returns

TypeDescription
null