Skip to content

Fix kernel lifecycle with warnings treated as errors - #1583

Open
JackyHsu-X wants to merge 2 commits into
ipython:mainfrom
JackyHsu-X:fix/kernel-lifecycle-warnings
Open

JackyHsu-X wants to merge 2 commits into
ipython:mainfrom
JackyHsu-X:fix/kernel-lifecycle-warnings

Conversation

@JackyHsu-X

@JackyHsu-X JackyHsu-X commented Oct 26, 2026 •

Copy link
Copy Markdown

Fixes #1582.

Prepare the main thread's event loop before starting the kernel. Handle Python 3.12's implicit-loop deprecation by explicitly creating a loop, while preserving an existing loop. Make IPythonKernel.do_shutdown() async, matching the base class and avoiding its synchronous-hook warning.

Seven regression cases cover unset, cleared and preconfigured loops, both shutdown restart flags, and real stock-launcher startup, execution, shutdown replies and clean process exits with warnings-as-errors. The subprocess cases explicitly opt into JUPYTER_PLATFORM_DIRS=1 so jupyter_core 5.1.0's unrelated path-migration warning does not terminate imports. Their strict warning policy remains enabled.

Validation:

  • Linux/Python 3.11.18 with all 54 package versions from the failed minimum-dependency CI job pinned: published tests reproduce its five failures; the revised cases plus direct shutdown tests pass all seven. The remote interpreter was 3.11.17, so this is not an identical runner image.
  • Original production with the revised tests still fails both lifecycle shutdown checks and both direct async-shutdown cases. Original production on Windows/Python 3.12.8 still fails the unset-loop case; configured and cleared loops pass.
  • Complete local Linux minimum suite: 236 passed, 18 skipped, one headless TkAgg failure reproduced on unchanged production with the same dependencies; 13 existing warnings retained. This is not a full-suite pass.
  • Existing Windows/Python 3.12.8: all five affected cases pass after the follow-up. The previous full-suite result on the initial patch was 180 passed, 32 skipped; it was not rerun for this test-only revision. Previous Linux/Python 3.12 results and typing baseline limits remain documented in the earlier validation.
  • Applicable official pre-commit hooks and diff checks pass for the revised tests. No new production typing result is claimed; the earlier official Windows mypy run had the same 15 baseline diagnostics on both production versions.

No production code changed in the minimum-dependency follow-up. No dependency, lockfile or CI changes. The full platform/Python/GUI matrix was not run locally, and remote CI must run on the revised head. The separate triage-label gate needs a maintainer.

AI disclosure: OpenAI Codex generated the changes and ran the investigation and validation. No independent human review is claimed.

Copy link
Copy Markdown
Author

The minimum-dependency failure occurs before the new cases reach the kernel lifecycle checks: jupyter_core 5.1.0 emits its platformdirs migration warning during import, and the child interpreters deliberately use warnings-as-errors.

The follow-up opts these two test functions into the documented JUPYTER_PLATFORM_DIRS=1 behavior using monkeypatch. PYTHONWARNINGS=error and -Werror remain enabled. Production code, warning filters, dependencies and CI are unchanged.

Validation:

  • Linux Python 3.11.18 with all 54 package versions from the failed job pinned: the published tests reproduce all five failures; the revised cases plus direct shutdown tests pass all seven.
  • Original production with these revised tests still fails both real shutdown lifecycles and both direct async-shutdown cases. On Windows/Python 3.12.8, its unset-loop case still fails while the two loop controls pass. The Linux reproduction uses Python 3.11.18 rather than the job's 3.11.17.
  • Complete local minimum suite: 236 passed, 18 skipped, one headless TkAgg failure. That same Tk failure also occurs on original production with the same dependencies; this is not a full-suite pass. The five affected Windows cases and applicable pre-commit hooks pass.

The remaining label gate requires a triage label such as bug from a maintainer. Remote CI will still need to run on the follow-up commit.

OpenAI Codex prepared and ran this investigation, revision and validation; no independent human review is claimed.

This branch has not been deployed

No deployments
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.

Stock ipykernel_launcher raises DeprecationWarning on startup and PendingDeprecationWarning on shutdown under PYTHONWARNINGS=error (Python 3.12+)

1 participant