@@ -268,18 +268,33 @@ def killChild(self, recursive=True):
268268
269269 :param boolean recursive: flag to kill all descendants
270270 """
271-
272- parent = psutil .Process (self .childPID )
273- children = parent .children (recursive = recursive )
274- children .append (parent )
275- for p in children :
271+ pgid = os .getpgid (self .childPID )
272+ if pgid != os .getpgrp ():
276273 try :
277- p .send_signal (signal .SIGTERM )
278- except psutil .NoSuchProcess :
274+ # Child is in its own group: kill the group
275+ os .killpg (pgid , signal .SIGTERM )
276+ except OSError :
277+ # Process is already dead
279278 pass
280- _gone , alive = psutil .wait_procs (children , timeout = 10 )
281- for p in alive :
282- p .kill ()
279+ else :
280+ # No separate group: walk the tree
281+ parent = psutil .Process (self .childPID )
282+ procs = parent .children (recursive = recursive )
283+ procs .append (parent )
284+ for p in procs :
285+ try :
286+ p .terminate ()
287+ except psutil .NoSuchProcess :
288+ pass
289+ _gone , alive = psutil .wait_procs (procs , timeout = 10 )
290+ # Escalate any survivors
291+ for p in alive :
292+ try :
293+ p .kill ()
294+ except psutil .NoSuchProcess :
295+ pass
296+
297+ self .childKilled = True
283298
284299 def pythonCall (self , function , * stArgs , ** stKeyArgs ):
285300 """call python function :function: with :stArgs: and :stKeyArgs:"""
@@ -405,7 +420,9 @@ def __readFromSystemCommandOutput(self, fd, bufferIndex):
405420 self .killChild ()
406421 return self .__generateSystemCommandError (1 , f"{ retDict ['Message' ]} for '{ self .cmdSeq } ' call" )
407422
408- def systemCall (self , cmdSeq , callbackFunction = None , shell = False , env = None , preexec_fn = None ):
423+ def systemCall (
424+ self , cmdSeq , callbackFunction = None , shell = False , env = None , preexec_fn = None , start_new_session = False
425+ ):
409426 """system call (no shell) - execute :cmdSeq:"""
410427
411428 if shell :
@@ -426,6 +443,7 @@ def systemCall(self, cmdSeq, callbackFunction=None, shell=False, env=None, preex
426443 env = env ,
427444 universal_newlines = True ,
428445 preexec_fn = preexec_fn ,
446+ start_new_session = start_new_session ,
429447 )
430448 self .childPID = self .child .pid
431449 except OSError as v :
0 commit comments