def _recursive_terminate(pid):
if sys.platform == "<STR_LIT:win32>":<EOL><INDENT>try:<EOL><INDENT>subprocess.check_output(<EOL>["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", str(pid)],<EOL>stderr=None)<EOL><DEDENT>except subprocess.CalledProcessError as e:<EOL><INDENT>if e.returncode not in [<NUM_LIT:1>, <NUM_LIT>, <NUM_LIT:255>]:<EOL><INDENT>raise<EOL><DEDENT>elif e.returncode == <NUM_LIT:1>:<EOL><INDENT>try:<EOL><INDENT>os.kill(pid, signal.SIGTERM)<EOL><DEDENT>except OSError as e:<EOL><INDENT>if e.errno != errno.ESRCH:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>children_pids = subprocess.check_output(<EOL>["<STR_LIT>", "<STR_LIT>", str(pid)],<EOL>stderr=None<EOL>)<EOL><DEDENT>except subprocess.CalledProcessError as e:<EOL><INDENT>if e.returncode == <NUM_LIT:1>:<EOL><INDENT>children_pids = b'<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>children_pids = children_pids.decode().split('<STR_LIT:\n>')[:-<NUM_LIT:1>]<EOL>for cpid in children_pids:<EOL><INDENT>cpid = int(cpid)<EOL>_recursive_terminate(cpid)<EOL><DEDENT>try:<EOL><INDENT>os.kill(pid, signal.SIGTERM)<EOL><DEDENT>except OSError as e:<EOL><INDENT>if e.errno != errno.ESRCH:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>
Recursively kill the descendants of a process before killing it.