Smithsonian / Smithsonian/layup

Worker pools are orphaned when layup is stopped in the background

Open
#562 0 comments 0 reactions 1 assignee View on GitHub

@Little-Ryugu is already working on this.

Since Sep 10, 2026.

Dominant language
Python
Stars
10
Forks
2
Avg merge
1d 43m
Merged PRs (30d)
58

Description

#523 and PR #561 cover the interactive case: Ctrl-C reaches the parent, which terminates the pool. A layup run started in the background is not covered, and this is the case that leaves processes running for days.

A shell backgrounding a job sets SIGINT to SIG_IGN, and the parent inherits it. The interrupt never arrives, so the except KeyboardInterrupt teardown never runs. Such a job is stopped with SIGTERM instead, whose default action kills the parent outright without unwinding, leaving the workers with PPID = 1.

Measured on a backgrounded parent with four workers, stopped by SIGTERM:

orphans left
as in #561 4
with a SIGTERM handler 0

Six such processes were found on one machine recently, PPID = 1 and five days old, in an environment nobody was still using.

Suggested fix, in _run_pool: install a SIGTERM handler that raises, so the existing teardown runs, and restore the previous handler in a finally so it does not leak into a caller's process.

def _terminate(signum, frame):
    raise KeyboardInterrupt

_prev_term = signal.signal(signal.SIGTERM, _terminate)
try:
    ...  # existing pool block
finally:
    signal.signal(signal.SIGTERM, _prev_term)

Two caveats: signal.signal only works on the main thread, so this should be skipped when layup is driven from a worker thread; and SIGKILL cannot be handled by anything.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.