Skip to content

Conversation

SkafteNicki
Copy link
Collaborator

@SkafteNicki SkafteNicki commented Aug 11, 2025

What does this PR do?

Fixes #20666
Fixes #20317

exit() and quit() are only guaranteed to be available in interactive envs, where the site module injects them. Thus, user are sometimes experiencing that they are missing (particular in jupyter notebook/lab). Also from the Python docs they are discourage to be used in production code:
https://docs.python.org/3/library/constants.html#constants-added-by-the-site-module

Use sys.exit instead which should always be available.

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--21052.org.readthedocs.build/en/21052/

@github-actions github-actions bot added fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package labels Aug 11, 2025
@bhimrazy
Copy link
Collaborator

We also seem to have a few exit() in upgrade_checkpoint.py. Should we replace them as part of this PR as well?


fyi: @SkafteNicki

@SkafteNicki
Copy link
Collaborator Author

We also seem to have a few exit() in upgrade_checkpoint.py. Should we replace them as part of this PR as well?

fyi: @SkafteNicki

@bhimrazy good call, fixed now :]

Copy link

codecov bot commented Aug 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87%. Comparing base (6a09f27) to head (53775da).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21052   +/-   ##
=======================================
  Coverage      87%      87%           
=======================================
  Files         268      268           
  Lines       23321    23324    +3     
=======================================
+ Hits        20313    20316    +3     
  Misses       3008     3008           

@Borda Borda merged commit 64d3112 into Lightning-AI:master Aug 11, 2025
115 checks passed
Borda pushed a commit that referenced this pull request Aug 13, 2025
* replace exit with sys.exit
* fix in upgrade checkpoint

(cherry picked from commit 64d3112)
Borda pushed a commit that referenced this pull request Aug 13, 2025
* replace exit with sys.exit
* fix in upgrade checkpoint

(cherry picked from commit 64d3112)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exit is not imported in lightning/pytorch/trainer/call.py Import error on shutdown/KeyboardInterrupt if ran from Jupyter Lab notebook cell

4 participants