Skip to content

Worker process hangs when SystemExit Exception is raised #220

Open

Description

@dxdc

When a worker in a multiprocess.Pool catches SIGTERM and raises SystemExit, the worker logs the signal handling but then hangs indefinitely. If the handler raises a different exception (e.g. ValueError), the process exits immediately as expected.

Observe that the worker logs the SIGTERM catch but the program never exits.

This appears to be catching Exception vs. BaseException (see PR)

hang_test.py

import logging
import os
import signal

from multiprocess import get_context

logging.basicConfig(
    level=logging.DEBUG,
    format="%(asctime)s %(levelname)-8s %(message)s",
)

def kill_worker_and_exit(x):
    def _handler(signum, frame):
        logging.debug(f"Worker {os.getpid()} caught SIGTERM on input={x}")
        raise SystemExit("worker received SIGTERM")

    signal.signal(signal.SIGTERM, _handler)
    os.kill(os.getpid(), signal.SIGTERM)

def multiprocess_hang():
    ctx = get_context()
    pool = ctx.Pool(processes=2, maxtasksperchild=1)
    for _ in pool.imap(kill_worker_and_exit, range(3)):
        pass

if __name__ == "__main__":
    multiprocess_hang()

Activity

  1. nnnaomina commented on Jan 9, 2026

    @nnnaomina

    I think I'm having the same issues

  2. nnnaomina commented on Jan 9, 2026

    @nnnaomina

    Since I'm not sure, I'm going to open a separate issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions