@@ -154,14 +154,22 @@ def pump_stream(cmdline: List[str], name: str, stream: Union[BinaryIO, TextIO],
154154 for t in threads :
155155 t .join (timeout = kill_after_timeout )
156156 if t .is_alive ():
157- if hasattr (process , 'proc' ): # Assume it is a Git.AutoInterrupt:
157+ if isinstance (process , Git .AutoInterrupt ) :
158158 process ._terminate ()
159159 else : # Don't want to deal with the other case
160- raise RuntimeError (f "Thread join() timed out in cmd.handle_process_output()."
161- " kill_after_timeout={kill_after_timeout} seconds" )
160+ raise RuntimeError ("Thread join() timed out in cmd.handle_process_output()."
161+ f " kill_after_timeout={ kill_after_timeout } seconds" )
162162 if stderr_handler :
163- stderr_handler ("error: process killed because it timed out."
164- f" kill_after_timeout={ kill_after_timeout } seconds" )
163+ error_str : Union [str , bytes ] = (
164+ "error: process killed because it timed out."
165+ f" kill_after_timeout={ kill_after_timeout } seconds" )
166+ if not decode_streams and isinstance (p_stderr , BinaryIO ):
167+ # Assume stderr_handler needs binary input
168+ error_str = cast (str , error_str )
169+ error_str = error_str .encode ()
170+ # We ignore typing on the next line because mypy does not like
171+ # the way we infered that stderr takes str of bytes
172+ stderr_handler (error_str ) # type: ignore
165173
166174 if finalizer :
167175 return finalizer (process )
@@ -404,7 +412,7 @@ class AutoInterrupt(object):
404412 def __init__ (self , proc : Union [None , subprocess .Popen ], args : Any ) -> None :
405413 self .proc = proc
406414 self .args = args
407- self .status = None
415+ self .status : Union [ int , None ] = None
408416
409417 def _terminate (self ) -> None :
410418 """Terminate the underlying process"""
@@ -447,8 +455,6 @@ def _terminate(self) -> None:
447455 call (("TASKKILL /F /T /PID %s 2>nul 1>nul" % str (proc .pid )), shell = True )
448456 # END exception handling
449457
450-
451-
452458 def __del__ (self ) -> None :
453459 self ._terminate ()
454460
@@ -465,11 +471,11 @@ def wait(self, stderr: Union[None, str, bytes] = b'') -> int:
465471 if stderr is None :
466472 stderr_b = b''
467473 stderr_b = force_bytes (data = stderr , encoding = 'utf-8' )
468-
474+ status : Union [ int , None ]
469475 if self .proc is not None :
470476 status = self .proc .wait ()
471477 p_stderr = self .proc .stderr
472- else : # Assume the underlying proc was killed earlier or never existed
478+ else : # Assume the underlying proc was killed earlier or never existed
473479 status = self .status
474480 p_stderr = None
475481
0 commit comments