code: def main() -> None:
      """Command-line wrapper to re-run a script whenever its source changes.
  
      Scripts may be specified by filename or module name::
  
          python -m tornado.autoreload -m tornado.test.runtests
          python -m tornado.autoreload tornado/test/runtests.py
  
      Running a script with this wrapper is similar to calling
      `tornado.autoreload.wait` at the end of the script, but this wrapper
      can catch import-time problems like syntax errors that would otherwise
      prevent the script from reaching its call to `wait`.
      """
      # Remember that we were launched with autoreload as main.
      # The main module can be tricky; set the variables both in our globals
      # (which may be __main__) and the real importable version.
      #
      # We use optparse instead of the newer argparse because we want to
      # mimic the python command-line interface which requires stopping
      # parsing at the first positional argument. optparse supports
      # this but as far as I can tell argparse does not.
      import optparse
      import tornado.autoreload
  
      global _autoreload_is_main
      global _original_argv, _original_spec
      tornado.autoreload._autoreload_is_main = (
          _autoreload_is_main
      ) = True
      original_argv = sys.argv
      tornado.autoreload._original_argv = _original_argv = original_argv
      original_spec = getattr(sys.modules["__main__"], "__spec__", None)
      tornado.autoreload._original_spec = _original_spec = original_spec
  
      parser = optparse.OptionParser(
          prog="python -m tornado.autoreload",
          usage=_USAGE,
          epilog="Either -m or a path must be specified, but not both",
      )
      parser.disable_interspersed_args()
      parser.add_option(
          "-m", dest="module", metavar="module", help="module to run"
      )
      parser.add_option(
          "--until-success",
          action="store_true",
          help="stop reloading after the program exist successfully (status code 0)",
      )
      opts, rest = parser.parse_args()
      if opts.module is None:
          if not rest:
              print(
                  "Either -m or a path must be specified",
                  file=sys.stderr,
              )
              sys.exit(1)
          path = rest[0]
          sys.argv = rest[:]
      else:
          path = None
          sys.argv = [sys.argv[0]] + rest
  
      # SystemExit.code is typed funny: https://github.com/python/typeshed/issues/8513
      # All we care about is truthiness
      exit_status: Union[int, str, None] = 1
      try:
          import runpy
  
          if opts.module is not None:
              runpy.run_module(
                  opts.module, run_name="__main__", alter_sys=True
              )
          else:
              assert path is not None
              runpy.run_path(path, run_name="__main__")
      except SystemExit as e:
          exit_status = e.code
          gen_log.info("Script exited with status %s", e.code)
      except Exception as e:
          gen_log.warning(
              "Script exited with uncaught exception", exc_info=True
          )
          # If an exception occurred at import time, the file with the error
          # never made it into sys.modules and so we won't know to watch it.
          # Just to make sure we've covered everything, walk the stack trace
          # from the exception and watch every file.
          for filename, lineno, name, line in traceback.extract_tb(
              sys.exc_info()[2]
          ):
              watch(filename)
          if isinstance(e, SyntaxError):
              # SyntaxErrors are special:  their innermost stack frame is fake
              # so extract_tb won't see it and we have to get the filename
              # from the exception object.
              if e.filename is not None:
                  watch(e.filename)
      else:
          exit_status = 0
          gen_log.info("Script exited normally")
      # restore sys.argv so subsequent executions will include autoreload
      sys.argv = original_argv
  
      if opts.module is not None:
          assert opts.module is not None
          # runpy did a fake import of the module as __main__, but now it's
          # no longer in sys.modules.  Figure out where it is and watch it.
          loader = pkgutil.get_loader(opts.module)
          if loader is not None and isinstance(
              loader, importlib.abc.FileLoader
          ):
              watch(loader.get_filename())
      if opts.until_success and not exit_status:
          return
      wait()
  
imports: import os
  import sys
  import functools
  import importlib.abc
  import os
  import pkgutil
  import sys
  import traceback
  import types
  import subprocess
  import weakref
  from tornado import ioloop
  from tornado.log import gen_log
  from tornado import process
  from typing import Callable, Dict, Optional, List, Union
label_desc: Use image node_id 8 for calling a global function with example usage: main() without return types