code: def close_api_gracefully(apis):
      _stop_event.set()
      try:
          for api in apis.values():
              try:
                  process = api["process"]
                  childs = get_child_pids(process.pid)
                  for p in childs:
                      try:
                          os.kill(p, signal.SIGTERM)
                      except Exception:
                          p.kill()
                  sys.stdout.flush()
                  process.terminate()
                  process.join()
                  sys.stdout.flush()
              except psutil.NoSuchProcess:
                  pass
      except KeyboardInterrupt:
          sys.exit(0)
  
imports: from mindsdb.utilities import log
  import os
  import sys
  import time
  import json
  import atexit
  import signal
  import psutil
  import asyncio
  import secrets
  import traceback
  import threading
  from textwrap import dedent
  from packaging import version
  from mindsdb.__about__ import __version__
  from mindsdb.api.http.start import start
  from mindsdb.api.mysql.start import start
  from mindsdb.api.mongo.start import start
  from mindsdb.api.postgres.start import start
  from mindsdb.interfaces.tasks.task_monitor import start
  from mindsdb.utilities.ml_task_queue.consumer import start
  from mindsdb.interfaces.jobs.scheduler import start
  from mindsdb.utilities.config import Config
  from mindsdb.utilities.ps import is_pid_listen_port, get_child_pids
  from mindsdb.utilities.functions import args_parse, get_versions_where_predictors_become_obsolete
  from mindsdb.interfaces.database.integrations import integration_controller
  import mindsdb.interfaces.storage.db
  from mindsdb.integrations.utilities.install import install_dependencies
  from mindsdb.utilities.fs import create_dirs_recursive, clean_process_marks, clean_unlinked_process_marks
  from mindsdb.utilities.telemetry import telemetry_file_exists, disable_telemetry
  from mindsdb.utilities.context import context
  from mindsdb.utilities.auth import register_oauth_client, get_aws_meta_data
label_desc: Use image node_id 1 for calling a global function with example usage: close_api_gracefully(apis) without return types