code: def main():
      import traceback
      import sys
      import getopt
  
      try:
          from pdb import Restart
      except ImportError:
  
          class Restart(Exception):
              pass
  
      if sys.version_info >= (3, 7):
          opts, args = getopt.getopt(
              sys.argv[1:], "mhc:", ["help", "command="]
          )
      else:
          opts, args = getopt.getopt(
              sys.argv[1:], "hc:", ["help", "command="]
          )
  
      commands = []
      run_as_module = False
      for opt, optarg in opts:
          if opt in ["-h", "--help"]:
              print(_usage)
              sys.exit()
          elif opt in ["-c", "--command"]:
              commands.append(optarg)
          elif opt in ["-m"]:
              run_as_module = True
  
      if not args:
          print(_usage)
          sys.exit(2)
  
      mainpyfile = args[0]  # Get script filename
      if not run_as_module and not os.path.exists(mainpyfile):
          print("Error:", mainpyfile, "does not exist")
          sys.exit(1)
  
      sys.argv = args  # Hide "pdb.py" from argument list
  
      # Replace pdb's dir with script's dir in front of module search path.
      if not run_as_module:
          sys.path[0] = os.path.dirname(mainpyfile)
  
      # Note on saving/restoring sys.argv: it's a good idea when sys.argv was
      # modified by the script being debugged. It's a bad idea when it was
      # changed by the user from the command line. There is a "restart" command
      # which allows explicit specification of command line arguments.
      pdb = _init_pdb(commands=commands)
      while 1:
          try:
              import pdb as stdlib_pdb
  
              if hasattr(stdlib_pdb.Pdb, "_run"):
                  # Looks like Pdb from Python 3.11+
                  if run_as_module:
                      pdb._run(stdlib_pdb._ModuleTarget(mainpyfile))
                  else:
                      pdb._run(stdlib_pdb._ScriptTarget(mainpyfile))
              else:
                  if run_as_module:
                      pdb._runmodule(mainpyfile)
                  else:
                      pdb._runscript(mainpyfile)
              if pdb._user_requested_quit:
                  break
              print("The program finished and will be restarted")
          except Restart:
              print("Restarting", mainpyfile, "with arguments:")
              print("\t" + " ".join(sys.argv[1:]))
          except SystemExit:
              # In most cases SystemExit does not warrant a post-mortem session.
              print(
                  "The program exited via sys.exit(). Exit status: ",
                  end="",
              )
              print(sys.exc_info()[1])
          except:
              traceback.print_exc()
              print(
                  "Uncaught exception. Entering post mortem debugging"
              )
              print("Running 'cont' or 'step' will restart the program")
              t = sys.exc_info()[2]
              pdb.interaction(None, t)
              print(
                  "Post mortem debugger finished. The "
                  + mainpyfile
                  + " will be restarted"
              )
  
imports: from __future__ import print_function
  import os
  import sys
  from decorator import contextmanager
  from IPython import get_ipython
  from IPython.core.debugger import BdbQuit_excepthook
  from IPython.terminal.ipapp import TerminalIPythonApp
  from IPython.terminal.embed import InteractiveShellEmbed
label_desc: Use image node_id 13 for calling a global function with example usage: main() without return types