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

Commit3f21391

Browse files
committed
Remove unused TASKKILL fallback in AutoInterrupt
When Git.AutoInterrupt was first implemented inead94f2, it usedos.kill (sending SIGINT to the process to terminate it). This wasin 2009, and not all supported versions of Python provided os.killon Windows, since it was added for Windows in 2.7 and 3.2 (2.6 and3.1 reached EoL in 2013 and 2012, respectively). CatchingAttributeError and running TASKKILL provided a fallback for Pythonversions in which os.kill was absent on Windows.Since then, all supported versions have os.kill on Windows, andalso the code of GitPython, in the try-block, has changed, and nolonger uses os.kill. It now contains four attribute accessexpressions:- proc.terminate. All currently suppported versions of Python (including 3.7, which GitPython still supports, and some before that) have Popen.terminate.- proc.wait. Same situation as proc.terminate. Popen.wait exists.- self._status_code_if_terminate. This is a class attribute of AutoInterrupt, accessible through its instances.- self.status. This is assigned to. AutoInterrupt is slotted, but "status" appears in __slots__, so this isn't an AttributeError either.The "except AttributeError" clause is thus no longer used and canbe removed, which is done here. Removing it shortens and simplifiesthe code, better expresses the logic for how the wrapped process isactually being terminated, and eliminates the need to engage withany subtleties of TASKKILL (and of how it is called) when readingthe code to verify its correctness.In addition, because they are now expected always to be available,if somehow an AttributeError managed to be raised in the terminateor wait calls, this would be very strange and we probably shouldn'tsilently catch that.(Because this AutoInterrupt._terminate method is sometimes calleddue to __del__ methods running as the interpreter is shutting down,it is possible for some attributes to unexpectedly be set to None,which could cause AttributeError indirectly if another attribute islooked up on the None object; and perhaps on some non-CPythonimplementations some attributes might even be deleted duringshutdown. The _terminate method handles this where relevant. Butthe TASKKILL fallback removed here seems unrelated to that, whichaffects module attributes and global variables. The names used inthe try-block are proc, status, and self, which are localvariables; the except clause itself accessed os.name, which used aglobal variable and a module attribute, indicating that the intentwas not to handle this interpreter shutdown scenario; and thiswhole issue, while not gone completely, is much less significantsince Python 3.4, due tohttps://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-442.)
1 parenta30b3b7 commit3f21391

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

‎git/cmd.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
importlogging
1212
importos
1313
importsignal
14-
fromsubprocessimportcall,Popen,PIPE,DEVNULL
14+
fromsubprocessimportPopen,PIPE,DEVNULL
1515
importsubprocess
1616
importthreading
1717
fromtextwrapimportdedent
@@ -544,16 +544,6 @@ def _terminate(self) -> None:
544544
self.status=self._status_code_if_terminateorstatus
545545
exceptOSErrorasex:
546546
log.info("Ignored error after process had died: %r",ex)
547-
exceptAttributeError:
548-
# Try Windows.
549-
# For some reason, providing None for stdout/stderr still prints something. This is why
550-
# we simply use the shell and redirect to nul. Slower than CreateProcess. The question
551-
# is whether we really want to see all these messages. It's annoying no matter what.
552-
ifos.name=="nt":
553-
call(
554-
("TASKKILL /F /T /PID %s 2>nul 1>nul"%str(proc.pid)),
555-
shell=True,
556-
)
557547
# END exception handling
558548

559549
def__del__(self)->None:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp