There was a problem hiding this comment.
Thanks a lot for the fix, looks good to me!
I will merge once CI is fixed.
Sorry, something went wrong.
There was a problem hiding this comment.
I've made two changes:
I plan to merge this once CI passes.
Sorry, something went wrong.
There was a problem hiding this comment.
Fixes a Windows interpreter-shutdown edge case where Git.AutoInterrupt._terminate() can raise AttributeError from subprocess.Popen.terminate() due to partially torn-down stdlib internals, preventing noisy “Exception ignored in: del” messages.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| git/cmd.py | Extends _AutoInterrupt._terminate() exception handling to include AttributeError during termination. |
| test/test_autointerrupt.py | Adds a focused regression test for AttributeError raised from terminate(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Sorry, something went wrong.
| # On interpreter shutdown (notably on Windows), parts of the stdlib used by | ||
| # subprocess can already be torn down (e.g. `subprocess._winapi` becomes None), | ||
| # which can cause AttributeError during terminate(). In that case, we prefer | ||
| # to silently ignore to avoid noisy "Exception ignored in: __del__" messages. |
There was a problem hiding this comment.
Catching AttributeError unconditionally here can mask real runtime failures when _terminate() is called outside interpreter shutdown (e.g. the kill_after_timeout path in handle_process_output). Consider only suppressing AttributeError during interpreter finalization (e.g. getattr(sys, "is_finalizing", lambda: False)()), and otherwise re-raising so unexpected terminate/wait breakages don’t silently leave processes running. Also, the comment says “silently ignore” but this logs at INFO—either adjust the wording or log level to match intent.
| # to silently ignore to avoid noisy "Exception ignored in: __del__" messages. | |
| # to log and ignore to avoid noisy "Exception ignored in: __del__" messages. | |
| if isinstance(ex, AttributeError) and not getattr(sys, "is_finalizing", lambda: False)(): | |
| # Outside interpreter finalization, an AttributeError here likely indicates | |
| # a real problem (e.g. broken subprocess internals), so re-raise it instead | |
| # of silently leaving the process running. | |
| raise |
Sorry, something went wrong.
There was a problem hiding this comment.
There may be some merit to this concern, but I don't think it needs to block the change here, since AttributeError really should not arise here in any other way. I'm also not entirely sure that a change along the lines of what the model suggests here would be robust enough to be worth doing. But probably some future change to make this more robust, or do log in more detail when the capability to do so is present, or both, could be worthwhile. (I reiterate that I don't consider this blocking.)
Sorry, something went wrong.
Fixes #2102
On Windows during interpreter shutdown, process objects can be partially torn down and terminate() may raise AttributeError (e.g. missing TerminateProcess).
This PR treats that similarly to the existing OSError handling in _AutoInterrupt._terminate() and adds a regression test covering the AttributeError case.
Tests: pytest -q test/test_autointerrupt.py