Remove unused TASKKILL fallback in AutoInterrupt by EliahKagan · Pull Request #1754 · gitpython-developers/GitPython (original) (raw)

When Git.AutoInterrupt was first implemented in ead94f2, it used os.kill (sending SIGINT to the process to terminate it). This was in 2009, and not all supported versions of Python provided os.kill on Windows, since it was added for Windows in 2.7 and 3.2 (2.6 and 3.1 reached EoL in 2013 and 2012, respectively). Catching AttributeError and running TASKKILL provided a fallback for Python versions in which os.kill was absent on Windows.

Since then, all supported versions have os.kill on Windows, and also the code of GitPython, in the try-block, has changed, and no longer uses os.kill. It now contains four attribute access expressions:

The except AttributeError clause is thus no longer used and can be removed, which is done here. Removing it shortens and simplifies the code, better expresses the logic for how the wrapped process is actually being terminated, and eliminates the need to engage with any subtleties of TASKKILL (and of how it is called) when reading the 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 terminate or wait calls, this would be very strange and we probably shouldn't silently catch that.


Because this AutoInterrupt._terminate method is sometimes called due to __del__ methods running as the interpreter is shutting down, it is possible for some attributes to unexpectedly be set to None. This could produce an indirect AttributeError due to 'NoneType' object has no attribute 'x'. Perhaps, one some non-CPython implementations, it could even result in some attributes being outright deleted. The _terminate method handles this where relevant.

But the TASKKILL fallback removed here seems unrelated to that, which affects module attributes and global variables. In contrast:

In addition, that whole issue, while not gone completely, is much less significant since Python 3.4.