code: def _terminate(pid: int):
      proc = psutil.Process(pid)
      sub_pids = [p.pid for p in proc.children(recursive=True)]
      proc.terminate()
      proc.wait(5)
      for p in sub_pids:
          try:
              proc = psutil.Process(p)
              proc.kill()
          except psutil.NoSuchProcess:
              continue
  
file_path: mars/mars/tests/test_cluster.py
imports: import asyncio
  import os
  import sys
  import subprocess
  import tempfile
  import psutil
  import pytest
  from ..None import new_session
  from ..None import tensor
  from ..services.cluster import NodeRole, WebClusterAPI
  from ..tests.core import flaky
  from ..utils import get_next_port
label_desc: Use image node_id 1 for calling a global function with example usage: _terminate(pid) without return types