Repository navigation
Conversation
- 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.
…eued compilations
| return executor(compilable) | ||
|
|
||
|
|
||
| def _cancel_pending_tasks_at_exit(pool: concurrent.futures.Executor) -> None: |
There was a problem hiding this comment.
I think I have an open PR which is in the same area dealing with crashes.
There was a problem hiding this comment.
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-groupSIGINTkills the idle workers. With this PR they survive it (no-op handler), so the only thing that stops them is the parent'sshutdown(). - If the parent dies on
SIGINTwithout finalizing the interpreter (an embedding host, or a parent with the defaultSIGINTdisposition), this branch leaves an orphaned worker blocked on the call queue. I reproduced this with your orphan script plussignal(SIGINT, SIG_DFL)andkillpg(SIGINT): one orphan on this branch, none onmain. 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 intest_runners.py). They don't conflict in behaviour: theSIGINThandler 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
There was a problem hiding this comment.
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.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
⚙️ Agent run details
|
## 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.
Summary
Running the
gt4py.nextdocumentation 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 withtags: [remove-stderr]or explain it away. This PR makes default usage quiet without adding anywarnings.filterwarningshack. It also replaces an opaque multiprocessing failure with an actionable error.UserWarning: Field View Program '<name>': Using Python execution, consider selecting a performance backend.on every embedded@gtx.programcallffront/decorator.py)UserWarning: Python is not running in optimized mode ...(added in #2538)config.WARN_PYTHON_DEBUG_MODE/GT4PY_WARN_PYTHON_DEBUG_MODE=1(default off)__debug__checks add overhead to every call. It is kept for benchmarking, but running without-Ois the norm in notebooks, scripts and tests, where the warning is only noise.Calling generic programs / direct calls to scan operators are not optimizedKeyboardInterrupttracebacks from the compile workers at notebook kernel shutdown / Ctrl-CSIGINTonce they exit by themselves when their parent dies, which #2870 adds. Otherwise, a parent killed bySIGINTwithout finalizing the interpreter (e.g. an embedding host) leaves the surviving workers orphaned. Details in this comment on #2870.if __name__ == "__main__":guard. It gets the multiprocessingRuntimeError"attempt to start a new process before ... bootstrapping", thenBrokenProcessPool__main__), but it now fails with a clear GT4Py errorNothing else of the same kind came up when running all the pages (see Testing).
Unguarded scripts (row 5) in detail
ProcessRunner.submitraises an explanatoryRuntimeErrornaming the program. It suggests guarding the entry point or settingGT4PY_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 insubmit, 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.BrokenProcessPoolthat the script then gets carries a note with the usual cause and the same remedies. The note is added once per error, inCompiledProgramsPool._load_artifact,wait_for_compilationandProcessRunner.submit.__main__,get_default_runner()returns but does not keep aProcessRunner. 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
__main__relies on the privatemultiprocessing.current_process()._inheritingflag. 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.wait_for_compilation()or a restart.Testing
test_program.py::test_embedded_program_call_is_silenttest_config.py:WARN_PYTHON_DEBUG_MODEis 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;BrokenProcessPoolhint in_load_artifact.test_runners.py:wait_for_compilation, gets the clear error in the worker and the hint in the script; the guarded control still works.submitrefuses to start a compilation while a child process imports__main__, but a runner can still be created.BrokenProcessPoolhints insubmitandwait_for_compilation, added once for an error shared by several futures.__main__import is not kept; a thread runner is.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 correspondingadd_hint_to_broken_pool_errorcall 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/user/next/workshop/exercises/6_where_domain_solution.ipynbare removed.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 theremove-stderrtags stripped.dsl/programs.mdandpython/running.md; the-Owarning inpython/running.mdandquickstart.md; workerKeyboardInterrupttracebacks at kernel shutdown.IPKernelAppTCP warning, plus the workerKeyboardInterrupttracebacks 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.