code: def auto_restart(args):
      """
      Subcommand to start a long-running subprocess and restart it
      on matched events.
  
      :param args:
          Command line argument options.
      """
      from watchdog.observers import Observer
      from watchdog.tricks import AutoRestartTrick
      import signal
      import re
  
      if not args.directories:
          args.directories = ["."]
  
      # Allow either signal name or number.
      if re.match("^SIG[A-Z]+$", args.signal):
          stop_signal = getattr(signal, args.signal)
      else:
          stop_signal = int(args.signal)
  
      # Handle SIGTERM in the same manner as SIGINT so that
      # this program has a chance to stop the child process.
      def handle_sigterm(_signum, _frame):
          raise KeyboardInterrupt()
  
      signal.signal(signal.SIGTERM, handle_sigterm)
  
      patterns, ignore_patterns = parse_patterns(
          args.patterns, args.ignore_patterns
      )
      command = [args.command]
      command.extend(args.command_args)
      handler = AutoRestartTrick(
          command=command,
          patterns=patterns,
          ignore_patterns=ignore_patterns,
          ignore_directories=args.ignore_directories,
          stop_signal=stop_signal,
          kill_after=args.kill_after,
      )
      handler.start()
      observer = Observer(timeout=args.timeout)
      observe_with(observer, handler, args.directories, args.recursive)
      handler.stop()
  
file_path: wandb/wandb/vendor/watchdog_0_9_0/wandb_watchdog/watchmedo.py
imports: import os.path
  import sys
  import yaml
  import time
  import logging
  from argh import arg, aliases, ArghParser, expects_obj
  from wandb_watchdog.version import VERSION_STRING
  from wandb_watchdog.utils import load_class
label_desc: Use image node_id 11 for calling a global function with example usage: auto_restart(args) without return types