@@ -154,14 +154,22 @@ def pump_stream(cmdline: List[str], name: str, stream: Union[BinaryIO, TextIO],
154
154
for t in threads :
155
155
t .join (timeout = kill_after_timeout )
156
156
if t .is_alive ():
157
- if hasattr (process , 'proc' ): # Assume it is a Git.AutoInterrupt:
157
+ if isinstance (process , Git .AutoInterrupt ) :
158
158
process ._terminate ()
159
159
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" )
162
162
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
165
173
166
174
if finalizer :
167
175
return finalizer (process )
@@ -404,7 +412,7 @@ class AutoInterrupt(object):
404
412
def __init__ (self , proc : Union [None , subprocess .Popen ], args : Any ) -> None :
405
413
self .proc = proc
406
414
self .args = args
407
- self .status = None
415
+ self .status : Union [ int , None ] = None
408
416
409
417
def _terminate (self ) -> None :
410
418
"""Terminate the underlying process"""
@@ -447,8 +455,6 @@ def _terminate(self) -> None:
447
455
call (("TASKKILL /F /T /PID %s 2>nul 1>nul" % str (proc .pid )), shell = True )
448
456
# END exception handling
449
457
450
-
451
-
452
458
def __del__ (self ) -> None :
453
459
self ._terminate ()
454
460
@@ -465,11 +471,11 @@ def wait(self, stderr: Union[None, str, bytes] = b'') -> int:
465
471
if stderr is None :
466
472
stderr_b = b''
467
473
stderr_b = force_bytes (data = stderr , encoding = 'utf-8' )
468
-
474
+ status : Union [ int , None ]
469
475
if self .proc is not None :
470
476
status = self .proc .wait ()
471
477
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
473
479
status = self .status
474
480
p_stderr = None
475
481
0 commit comments