Skip to content

process

dev_tool.tools.process

INTERRUPT_ESCALATION_SECONDS = 0.5 module-attribute

PR_SET_PDEATHSIG = 1 module-attribute

child_preexec

A function that prepares a POSIX child process before exec.

The child is placed in its own session so signals can be delivered to its whole process group, and the parent-death signal ensures the child dies with this process even on an abnormal exit. The death signal is SIGTERM rather than SIGKILL because the signal is not inherited by grandchildren: a graceful signal lets the child (such as Django's autoreloader) shut down its own children before exiting.

Source code in dev_tool/tools/process.py
def child_preexec() -> None:
    """
    A function that prepares a POSIX child process before exec.

    The child is placed in its own session so signals can be delivered to
    its whole process group, and the parent-death signal ensures the child
    dies with this process even on an abnormal exit. The death signal is
    SIGTERM rather than SIGKILL because the signal is not inherited by
    grandchildren: a graceful signal lets the child (such as Django's
    autoreloader) shut down its own children before exiting.
    """

    os.setsid()

    if _libc is not None:
        _libc.prctl(PR_SET_PDEATHSIG, signal.SIGTERM, 0, 0, 0)