Skip to content

fix[next]: quiet warnings and worker noise in default usage - #3022

Open
egparedes wants to merge 9 commits into
GridTools:mainfrom
egparedes:next-quiet-docs-warnings
Open

egparedes wants to merge 9 commits into
GridTools:mainfrom
egparedes:next-quiet-docs-warnings

Conversation

@egparedes

@egparedes egparedes commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Running the gt4py.next documentation examples produced stderr noise from GT4Py itself. The examples are MyST notebooks executed with myst-nb / nox -s test_examples, and the docs currently hide this noise with tags: [remove-stderr] or explain it away. This PR makes default usage quiet without adding any warnings.filterwarnings hack. It also replaces an opaque multiprocessing failure with an actionable error.

# Noise Change Why
1 UserWarning: Field View Program '<name>': Using Python execution, consider selecting a performance backend. on every embedded @gtx.program call Removed (ffront/decorator.py) Embedded execution is the documented default and the recommended development mode. The warning fired constantly in docs, tests and notebooks.
2 UserWarning: Python is not running in optimized mode ... (added in #2538) Now opt-in: config.WARN_PYTHON_DEBUG_MODE / GT4PY_WARN_PYTHON_DEBUG_MODE=1 (default off) The hint is deliberate: the __debug__ checks add overhead to every call. It is kept for benchmarking, but running without -O is the norm in notebooks, scripts and tests, where the warning is only noise.
3 Calling generic programs / direct calls to scan operators are not optimized Left as is It points at the user's call site (tested) and is actionable. It only fires for a direct scan-operator call with a compiled backend, and the user guide documents it in a tip. It does not fire in any docs page.
4 KeyboardInterrupt tracebacks from the compile workers at notebook kernel shutdown / Ctrl-C Not in this PR, left to #2870 Idle workers can only safely survive a process-group SIGINT once they exit by themselves when their parent dies, which #2870 adds. Otherwise, a parent killed by SIGINT without finalizing the interpreter (e.g. an embedding host) leaves the surviving workers orphaned. Details in this comment on #2870.
5 A plain script calls a compiled program at module level, without an if __name__ == "__main__": guard. It gets the multiprocessing RuntimeError "attempt to start a new process before ... bootstrapping", then BrokenProcessPool Still not supported (spawn workers re-import __main__), but it now fails with a clear GT4Py error See below.

Nothing else of the same kind came up when running all the pages (see Testing).

Unguarded scripts (row 5) in detail

  • Clear error in the worker: ProcessRunner.submit raises an explanatory RuntimeError naming the program. It suggests guarding the entry point or setting GT4PY_BUILD_JOBS_MODE=serial. It fires when a compilation would start worker processes while a spawn/forkserver child process is importing the main module. The check is in submit, right before the pool is used, not in __init__: creating a runner starts no process, so a module-level runner stays harmless for the script's own child processes.
  • Hint in the script: the BrokenProcessPool that the script then gets carries a note with the usual cause and the same remedies. The note is added once per error, in CompiledProgramsPool._load_artifact, wait_for_compilation and ProcessRunner.submit.
  • Default runner: while a child process is importing __main__, get_default_runner() returns but does not keep a ProcessRunner. That way the child still gets the serial default of worker processes once it is set up. Thread and serial runners are kept as before.

Worth a look

  • Detecting a child process that imports __main__ relies on the private multiprocessing.current_process()._inheriting flag. The stdlib itself uses it in _check_not_importing_main, and it is set the same way on 3.12-3.14. If it disappeared, the check would silently fall back to the previous stdlib error.
  • Not done: resetting the default runner when the pool breaks. For example, an OOM-killed worker leaves a notebook session with a broken pool until wait_for_compilation() or a restart.

Testing

  • New / updated tests:
    • test_program.py::test_embedded_program_call_is_silent
    • test_config.py: WARN_PYTHON_DEBUG_MODE is off by default (checked in a fresh interpreter).
    • test_compiled_program.py: the debug-mode warning is absent when disabled and issued once when opted in; BrokenProcessPool hint in _load_artifact.
    • test_runners.py:
      • An unguarded script, going through the default runner and wait_for_compilation, gets the clear error in the worker and the hint in the script; the guarded control still works.
      • submit refuses to start a compilation while a child process imports __main__, but a runner can still be created.
      • BrokenProcessPool hints in submit and wait_for_compilation, added once for an error shared by several futures.
      • A default process runner made during the __main__ import is not kept; a thread runner is.
    • The behaviour-changing tests fail on origin/main. The controls (the guarded script, creating a runner during the __main__ import, the cached thread runner) pass there by design. The hint tests fail when the corresponding add_hint_to_broken_pool_error call is removed.
  • uv run pytest tests/next_tests/unit_tests/otf_tests tests/next_tests/unit_tests/test_config.py tests/next_tests/integration_tests/feature_tests/ffront_tests/test_program.py: all pass. uv run pre-commit run (ruff, mypy, tach) passes. The full CI matrix was not run locally.
  • Docs: the stale embedded-execution warnings saved in the outputs of docs/user/next/workshop/exercises/6_where_domain_solution.ipynb are removed.
  • Docs corpus: I executed the pages of the user guide (branch docs-next-user-guide, PR docs: unified user documentation site with cartesian and next subsites #3005; read-only, not part of this PR) and the workshop notebooks with the remove-stderr tags stripped.
    • Before: embedded-program warnings in dsl/programs.md and python/running.md; the -O warning in python/running.md and quickstart.md; worker KeyboardInterrupt tracebacks at kernel shutdown.
    • After: the warnings are gone. The only remaining stderr output is Jupyter's own IPKernelApp TCP warning, plus the worker KeyboardInterrupt tracebacks at kernel shutdown, which stay until fix[next]: exit compile-pool workers when their parent dies #2870 handles them.

🤖 Written by an agent on my behalf.

- Do not warn on every embedded `@gtx.program` call: embedded execution is the
  documented default for development.
- Make the "not running with python -O" hint opt-in via
  `GT4PY_WARN_PYTHON_DEBUG_MODE` (`config.WARN_PYTHON_DEBUG_MODE`).
- Compilation workers ignore SIGINT, so Ctrl-C / Jupyter kernel shutdown no
  longer prints `KeyboardInterrupt` tracebacks from the workers nor breaks the
  pool; queued compilations are cancelled at interpreter exit.
- Calling a compiled program at module level of a script without an
  `if __name__ == "__main__":` guard now fails with an actionable error instead
  of the bare multiprocessing bootstrapping `RuntimeError`.
…mpilations at exit

Address review: workers install a no-op SIGINT handler instead of SIG_IGN (the
latter is inherited by cmake/ninja, making Ctrl-C ineffective), queued
compilations are cancelled from a threading exit hook (running before the
concurrent.futures one that would drain the queue), drop the Runner.shutdown
API change, fix the config option placement, hint on submit to a broken pool,
and replace the signal tests by subprocess scenarios.
Comment thread src/gt4py/next/otf/runners.py Outdated
return executor(compilable)


def _cancel_pending_tasks_at_exit(pool: concurrent.futures.Executor) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have an open PR which is in the same area dealing with crashes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, #2870 ("exit compile-pool workers when their parent dies"). The two PRs complement each other, and this one actually needs #2870:

  • On main, a process-group SIGINT kills the idle workers. With this PR they survive it (no-op handler), so the only thing that stops them is the parent's shutdown().
  • If the parent dies on SIGINT without finalizing the interpreter (an embedding host, or a parent with the default SIGINT disposition), this branch leaves an orphaned worker blocked on the call queue. I reproduced this with your orphan script plus signal(SIGINT, SIG_DFL) and killpg(SIGINT): one orphan on this branch, none on main. The parent-sentinel watcher in fix[next]: exit compile-pool workers when their parent dies #2870 is exactly what closes this.
  • The two only touch the same lines textually (_pool_worker_initializer, the imports and helpers in test_runners.py). They don't conflict in behaviour: the SIGINT handler and the parent watcher work independently.

My proposal: land #2870 first, then rebase this PR on top of it and add the SIGINT + dead-parent case to the orphan test. Or I can stack this PR on your branch if you prefer.

🤖 Written by an agent on behalf of the user

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: change of plan. Instead of waiting for #2870 or stacking on it, this PR now drops everything that depends on it: the SIGINT handler of the workers, the exit hook cancelling queued compilations, and their tests (3264d3c). Those parts belong in #2870 now. This comment there describes them, with a link to the full code and tests: #2870 (comment)

With that, the two PRs no longer overlap and can land in either order.

🤖 Written by an agent on behalf of the user

…2870

Without the parent watcher of GridTools#2870, workers that survive a process-group
SIGINT are orphaned when the parent dies without finalizing the interpreter
(e.g. an embedding host). Drop the no-op SIGINT handler of the workers and,
with it, the exit hook cancelling queued compilations, which was only needed
because workers no longer died on Ctrl-C.
- Name the child process generically in the '__main__' import guard: the
  stdlib flag is set for any spawn/forkserver child, not only GT4Py workers.
- Check the actual default of WARN_PYTHON_DEBUG_MODE in test_config.
- Cover the BrokenProcessPool hint added in ProcessRunner.submit.
- Neutral names in the guarded/unguarded script test.
- Drop the stale embedded-execution warnings saved in a workshop notebook.
… child imports __main__

Creating a ProcessRunner starts no process, so a module-level runner in a
script must not break the script's own spawn children. The guard now sits in
submit, right before the pool is used.

Tests: the unguarded-script test goes through the default runner and
wait_for_compilation and checks the hint reaches the script; the
wait_for_compilation hint is covered directly; the embedded-call test only
looks for the removed warning.
…ports __main__

Since the guard moved into submit, get_default_runner could cache a
ProcessRunner in a child process that was still importing the main module,
so the child would not get the serial default once set up.
…ports __main__

Other runners are kept as usual, so that they do not pile up (and leave idle
threads behind) when a module compiles several programs during that phase.
@egparedes
egparedes marked this pull request as ready for review November 23, 2026 18:52
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
✅ Merge recommendation: Needs review
🔎 Failure modes

What: The detection of "a child process is importing `__main__`" relies on the private stdlib flag `multiprocessing.current_process()._inheriting` (set in `multiprocessing.spawn._main`). If a supported CPython version renames or removes this attribute, the check silently returns False: the guard in `ProcessRunner.submit` stops firing and unguarded scripts regress to the bare multiprocessing "bootstrapping phase" RuntimeError / BrokenProcessPool instead of the new actionable error. The code defensively defaults to False, so the failure is a silent loss of the new diagnostics, not a crash.
Where: src/gt4py/next/otf/runners.py:_is_importing_main_module_in_child_process
Trigger: A future CPython release within the supported range (3.12-3.14 or later) changing the private `_inheriting` attribute in `multiprocessing.spawn`.
Detected by: The subprocess test `test_unguarded_script_fails_with_a_clear_message` in tests/next_tests/unit_tests/otf_tests/test_runners.py failing once CI runs on an affected Python version.
Covered in this PR: Yes

What: The new end-to-end test spawns real compilation worker processes and asserts on stderr text with a 300 s timeout; on a heavily loaded CI runner, worker startup or the compile could exceed the timeout, producing flaky failures of an otherwise correct implementation.
Where: tests/next_tests/unit_tests/otf_tests/test_runners.py:test_unguarded_script_fails_with_a_clear_message
Trigger: Slow or loaded CI machine executing the next test matrix.
Detected by: Intermittent CI timeout/failure of this specific test.
Covered in this PR: No

🏅 Score: 88
🧪 PR contains tests
🔒 No security concerns identified
🔀 Multiple PR themes

Sub-PR theme: fix[next]: drop embedded-execution warning and make the python -O hint opt-in

Relevant files:

  • src/gt4py/next/config.py
  • src/gt4py/next/ffront/decorator.py
  • src/gt4py/next/otf/compiled_program.py
  • tests/next_tests/integration_tests/feature_tests/ffront_tests/test_program.py
  • tests/next_tests/unit_tests/otf_tests/test_compiled_program.py
  • tests/next_tests/unit_tests/test_config.py
  • docs/user/next/workshop/exercises/6_where_domain_solution.ipynb

Sub-PR theme: fix[next]: actionable errors for broken compilation pools and unguarded scripts

Relevant files:

  • src/gt4py/next/otf/runners.py
  • src/gt4py/next/otf/compiled_program.py
  • tests/next_tests/unit_tests/otf_tests/test_runners.py
  • tests/next_tests/unit_tests/otf_tests/test_compiled_program.py

⚡ No major issues detected

⚙️ Agent run details
  • Model: openai/zai-org/GLM-5.3-Flash
  • Tokens: 15,851 in / 24,180 out / 40,031 total
  • Time cost: 184.1s
  • AI calls: 1

egparedes added a commit that referenced this pull request Nov 23, 2026
## Description

Follows #3023 (documentation site infrastructure, already merged).
Replaces the placeholder page of the `gt4py.next` subsite with new user
documentation, written from scratch as executed MyST notebooks: every
code cell runs when the site is built, so the outputs shown are the real
ones and a failing example fails the build.

The goal is a short and clear guide, not a complete reference:

| Section | Pages |
| --- | --- |
| Getting started | Landing page, quickstart |
| Data structures | Grids and fields (dimensions, domains, allocation,
unstructured meshes) |
| GT4Py DSL | Field operators, premap and neighbors (Cartesian,
unstructured, `concat_where`, staggered dimensions), scan operators,
programs |
| Execution | Executing GT4Py programs: embedded execution, compiled
backends (`dace_cpu`, `gtfn_cpu`), build cache, compiling in advance,
static parameters, static domains, short GPU note |

The worked examples (horizontal diffusion, implicit vertical diffusion,
operators on an unstructured mesh) are split out to #3032, stacked on
this PR, to be reviewed separately.

### Other changes

- `test_examples` nox session: runs every executable page of the
`gt4py.next` subsite, in any of its folders, including the landing page.
- The toolchain guides (`HackTheToolchain.md`, `WorkflowPatterns.md`)
move from `docs/user/next/advanced/` to
`docs/development/next/toolchain/`, since they are developer
documentation. They are still run by `test_examples`.
- The figures of the small unstructured mesh are generated by a script,
`docs/user/next/images/mesh_figures.py`, from the same tables used in
the pages.
- The `gt4py.cartesian` site is now titled "GT4Py Cartesian" instead of
"GT4Py (cartesian)".
- `Documentation` workflow: the site can also be deployed manually from
`main` (workflow dispatch with the `deploy` input), not only from a
release tag.
- The Sphinx configuration of the `gt4py.next` subsite drops the DaCe
SDFG viewer scripts which importing `dace` injects in the notebook
outputs, since they slowed down the loading of every page.
- Welcome page card and `docs/development/tools/documentation.md`
updated to describe the new content.

### Notes

- There is no API reference for `gt4py.next`: the docstrings of the
public API are not ready to be published yet.
- `concat_where` and staggered dimensions are documented and marked as
experimental.
- The GPU section is not executed in the build.
- Some cells hide warnings printed to stderr (`remove-stderr` tag).
#3022 removes those warnings in the library; the tags can be dropped
once it is merged.
- This content was previously part of #3005, where the first review
comments are.

## Requirements

- [x] All fixes and/or new features come with corresponding tests: the
pages are executed in the docs build and by the `test_examples` session.
- [ ] Important design decisions have been documented in the appropriate
ADR inside the [docs/development/ADRs/](docs/development/ADRs/README.md)
folder: not applicable.

🤖 Written by an agent on my behalf.

This branch was previously deployed

1 inactive deployment
pr-agent — f0b71b4c Deployed Nov 23, 2026 by egparedes via pr-agent / pr-agent #180
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants