Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: guard AutoInterrupt terminate during interpreter shutdown#2105

Merged
EliahKagan merged 2 commits intogitpython-developers:mainfrom
lweyrich1:fix-autointerrupt-shutdown-guard
Mar 9, 2026
Merged

fix: guard AutoInterrupt terminate during interpreter shutdown#2105
EliahKagan merged 2 commits intogitpython-developers:mainfrom
lweyrich1:fix-autointerrupt-shutdown-guard

Conversation

@lweyrich1
Copy link
Contributor

Fixes#2102

On Windows during interpreter shutdown, process objects can be partially torn down andterminate() may raiseAttributeError (e.g. missingTerminateProcess).

This PR treats that similarly to the existingOSError handling in_AutoInterrupt._terminate() and adds a regression test covering theAttributeError case.

Tests:pytest -q test/test_autointerrupt.py

Copy link
Member

@ByronByron left a comment
edited
Loading

Choose a reason for hiding this comment

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

Thanks a lot for the fix, looks good to me!

I will merge once CI is fixed.

@EliahKaganEliahKaganforce-pushed thefix-autointerrupt-shutdown-guard branch fromdae9b25 to357aad1CompareMarch 9, 2026 17:56
Copy link
Member

@EliahKaganEliahKagan left a comment

Choose a reason for hiding this comment

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

I've made two changes:

  • Rebased this onto main after merging#2108 to fix#2107 (which arose more recently than#2105 (review) and is not due to changes here, but would have appeared here next time CI ran).
  • Fixed the blocker mentioned in#2105 (review) where the lint job failed. This was due to an unnecessaryimport pytest (since the module does not use anything from thepytest module in its own code).

I plan to merge this once CI passes.

Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Windows interpreter-shutdown edge case whereGit.AutoInterrupt._terminate() can raiseAttributeError fromsubprocess.Popen.terminate() due to partially torn-down stdlib internals, preventing noisy “Exception ignored in:del” messages.

Changes:

  • TreatAttributeError fromproc.terminate() similarly to existingOSError handling in_AutoInterrupt._terminate().
  • Add a regression test that simulatesterminate() raisingAttributeError and asserts_terminate() does not raise and clearsproc.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

FileDescription
git/cmd.pyExtends_AutoInterrupt._terminate() exception handling to includeAttributeError during termination.
test/test_autointerrupt.pyAdds a focused regression test forAttributeError raised fromterminate().

💡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.

# 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.
Copy link

CopilotAIMar 9, 2026

Choose a reason for hiding this comment

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

Catching AttributeError unconditionally here can mask real runtime failures when_terminate() is called outside interpreter shutdown (e.g. thekill_after_timeout path inhandle_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.

Suggested change
# tosilently ignore to avoid noisy "Exception ignored in: __del__" messages.
# tolog and ignore to avoid noisy "Exception ignored in: __del__" messages.
ifisinstance(ex,AttributeError)andnotgetattr(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

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

There may be some merit to this concern, but I don't think it needs to block the change here, sinceAttributeError 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.)

@EliahKaganEliahKagan merged commite23c548 intogitpython-developers:mainMar 9, 2026
31 checks passed
@EliahKagan
Copy link
Member

Thanks@lweyrich1!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@EliahKaganEliahKaganEliahKagan approved these changes

Copilot code reviewCopilotCopilot left review comments

@ByronByronByron approved these changes

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AttributeError: 'NoneType' object has no attribute 'TerminateProcess' when accessing tree during iter_commits

4 participants

@lweyrich1@EliahKagan@Byron

[8]ページ先頭

©2009-2026 Movatter.jp