@@ -138,7 +138,7 @@ def handle_process_output(
138138 - decoding must happen later, such as for :class:`~git.diff.Diff`\s.
139139
140140 :param kill_after_timeout:
141- :class:`int`, `float`, or ``None`` (block indefinitely), Default = ``None``.
141+ :class:`` int`` , `` float` `, or ``None`` (block indefinitely), Default = ``None``.
142142
143143 To specify a timeout in seconds for the git command, after which the process
144144 should be killed.
@@ -373,7 +373,7 @@ def _terminate(self) -> None:
373373 status = proc .wait (timeout = self .timeout ) # Ensure the process goes away.
374374
375375 self .status = self ._status_code_if_terminate or status
376- except (OSError , AttributeError ) as ex :
376+ except (OSError , AttributeError , subprocess . TimeoutExpired ) as ex :
377377 # On interpreter shutdown (notably on Windows), parts of the stdlib used by
378378 # subprocess can already be torn down (e.g. `subprocess._winapi` becomes None),
379379 # which can cause AttributeError during terminate(). In that case, we prefer
@@ -1111,7 +1111,7 @@ def execute(
11111111 as_process : bool = False ,
11121112 output_stream : Union [None , BinaryIO ] = None ,
11131113 stdout_as_string : bool = True ,
1114- kill_after_timeout : Union [ None , float ] = None ,
1114+ kill_after_timeout : float | int | None = None ,
11151115 with_stdout : bool = True ,
11161116 universal_newlines : bool = False ,
11171117 shell : Union [None , bool ] = None ,
@@ -1163,13 +1163,12 @@ def execute(
11631163 until the timeout is explicitly specified. Uses of this feature should be
11641164 carefully considered, due to the following limitations:
11651165
1166- 1. This feature is not supported at all on Windows.
1167- 2. Effectiveness may vary by operating system. ``ps --ppid`` is used to
1166+ 1. Effectiveness may vary by operating system. ``ps --ppid`` is used to
11681167 enumerate child processes, which is available on most GNU/Linux systems
11691168 but not most others.
1170- 3 . Deeper descendants do not receive signals, though they may sometimes
1169+ 2 . Deeper descendants do not receive signals, though they may sometimes
11711170 terminate as a consequence of their parent processes being killed.
1172- 4 . `kill_after_timeout` uses ``SIGKILL``, which can have negative side
1171+ 3 . `kill_after_timeout` uses ``SIGKILL``, which can have negative side
11731172 effects on a repository. For example, stale locks in case of
11741173 :manpage:`git-gc(1)` could render the repository incapable of accepting
11751174 changes until the lock is manually removed.
@@ -1257,15 +1256,7 @@ def execute(
12571256 if inline_env is not None :
12581257 env .update (inline_env )
12591258
1260- if sys .platform == "win32" :
1261- if kill_after_timeout is not None :
1262- raise GitCommandError (
1263- redacted_command ,
1264- '"kill_after_timeout" feature is not supported on Windows.' ,
1265- )
1266- cmd_not_found_exception = OSError
1267- else :
1268- cmd_not_found_exception = FileNotFoundError
1259+ cmd_not_found_exception = OSError if sys .platform == "win32" else FileNotFoundError
12691260 # END handle
12701261
12711262 stdout_sink = PIPE if with_stdout else getattr (subprocess , "DEVNULL" , None ) or open (os .devnull , "wb" )
@@ -1335,6 +1326,12 @@ def execute(
13351326 stderr_value = stderr_value [:- 1 ]
13361327 status = proc .wait (timeout = kill_after_timeout )
13371328 # END stdout handling
1329+ except subprocess .TimeoutExpired as err :
1330+ _logger .info (
1331+ "error: process killed because it timed out. kill_after_timeout=%s seconds" , kill_after_timeout ,
1332+ )
1333+ if with_exceptions :
1334+ raise GitCommandError (redacted_command , status or 255 , err .stderr , err .stdout ) from err
13381335 finally :
13391336 if proc .stdout is not None :
13401337 proc .stdout .close ()
0 commit comments