code: def stop_mindsdb(ports=None):
      mdb_ports = [47334, 47335, 47336]
      if isinstance(ports, list):
          mdb_ports = mdb_ports + ports
      procs = [
          x
          for x in net_connections()
          if x.pid is not None and x.laddr[1] in mdb_ports
      ]
      print(f"Found {len(procs)} MindsDB processes")
  
      if len(procs) == 0:
          print("Nothing to close")
          return
  
      for proc in procs:
          print(f" -- {proc.pid} / {proc.laddr[1]} / {proc.status}")
  
      pid_port = set((x.pid, x.laddr[1]) for x in procs)
  
      interrupted_pids = []
      for pid, port in pid_port:
          if pid is None:
              print(f"Can not release {port} because it occupied by OS")
          elif pid not in interrupted_pids:
              try:
                  p = psutil.Process(pid)
                  print(f"Send SIGINT to {pid}/{[port]}")
                  p.send_signal(signal.SIGINT)
                  interrupted_pids.append(pid)
              except psutil.NoSuchProcess:
                  pass
              except Exception as e:
                  print(f"Can not interrupt process {pid}: {e}")
  
      waited_for = 0
      waited_ports = [
          x for x in net_connections() if x.laddr[1] in mdb_ports
      ]
      while len(waited_ports) > 0 and waited_for < 30:
          print(
              f"\nSome mindsdb ports are yet to die, waiting for them to do so: {[(x.pid, x.laddr[1], x.status) for x in waited_ports]}. Waited for a total of: {waited_for} seconds\n"
          )
          time.sleep(2)
          waited_for += 2
          waited_ports = [
              x for x in net_connections() if x.laddr[1] in mdb_ports
          ]
      if waited_for >= 30:
          raise Exception("Some mindsdb ports can`t die.")
  
imports: import time
  import os
  import json
  import subprocess
  import atexit
  import asyncio
  import re
  import sys
  from pathlib import Path
  import signal
  import psutil
  import requests
  from pandas import DataFrame
  from ps import wait_port, is_port_in_use, net_connections
label_desc: Use image node_id 4 for calling a global function with example usage: stop_mindsdb(ports) without return types