code: def _patch_module(
      module,
      prefix="",
      basepath=None,
      basemodule=None,
      exclude_prefixes=[],
      only_prefix=[],
  ):
      if isinstance(module, str):
          if basemodule is None:
              basemodule = module + "."
              import importlib
  
              importlib.import_module(module)
          module = sys.modules.get(module)
          if not module:
              return
          if not basepath:
              basepath = (
                  os.path.sep.join(
                      module.__file__.split(os.path.sep)[:-1]
                  )
                  + os.path.sep
              )
  
      # only sub modules
      if not hasattr(module, "__file__") or (
          inspect.ismodule(module)
          and not module.__file__.startswith(basepath)
      ):
          if hasattr(
              module, "__module__"
          ) and module.__module__.startswith(basemodule):
              # this is one of ours
              pass
          else:
              # print('Skipping: {}'.format(module))
              return
  
      # Do not patch ourselves
      if hasattr(module, "__file__") and module.__file__ == __file__:
          return
  
      prefix += module.__name__.split(".")[-1] + "."
  
      # Do not patch low level network layer
      if (
          prefix.startswith("clearml.backend_api.session.")
          and prefix != "clearml.backend_api.session."
      ):
          if (
              not prefix.endswith(".Session.")
              and ".token_manager." not in prefix
          ):
              # print('SKIPPING: {}'.format(prefix))
              return
      if prefix.startswith("clearml.backend_api.services."):
          return
  
      for skip in exclude_prefixes:
          if prefix.startswith(skip):
              return
  
      for fn in (m for m in dir(module) if not m.startswith("__")):
          if fn in ("schema_property") or fn.startswith(
              "_PostImportHookPatching__"
          ):
              continue
          # noinspection PyBroadException
          try:
              fnc = getattr(module, fn)
          except Exception:
              continue
          if inspect.ismodule(fnc):
              _patch_module(
                  fnc,
                  prefix=prefix,
                  basepath=basepath,
                  basemodule=basemodule,
                  exclude_prefixes=exclude_prefixes,
                  only_prefix=only_prefix,
              )
          elif inspect.isclass(fnc):
              _patch_module(
                  fnc,
                  prefix=prefix,
                  basepath=basepath,
                  basemodule=basemodule,
                  exclude_prefixes=exclude_prefixes,
                  only_prefix=only_prefix,
              )
          elif inspect.isroutine(fnc):
              if only_prefix and all(
                  p not in (prefix + str(fn)) for p in only_prefix
              ):
                  continue
  
              for skip in exclude_prefixes:
                  if (prefix + str(fn)).startswith(skip):
                      continue
  
              # _log_stderr('Patching: {}'.format(prefix+fn))
  
              if inspect.isclass(module):
                  # check if this is even in our module
                  if (
                      hasattr(fnc, "__module__")
                      and fnc.__module__ != module.__module__
                  ):
                      pass  # print('not ours {} {}'.format(module, fnc))
                  elif hasattr(
                      fnc, "__qualname__"
                  ) and fnc.__qualname__.startswith(
                      module.__name__ + "."
                  ):
                      if isinstance(module.__dict__[fn], classmethod):
                          setattr(
                              module,
                              fn,
                              _traced_call_cls(prefix + fn, fnc),
                          )
                      elif isinstance(
                          module.__dict__[fn], staticmethod
                      ):
                          setattr(
                              module,
                              fn,
                              _traced_call_static(prefix + fn, fnc),
                          )
                      else:
                          setattr(
                              module,
                              fn,
                              _traced_call_method(prefix + fn, fnc),
                          )
                  else:
                      # probably not ours hopefully static function
                      if hasattr(
                          fnc, "__qualname__"
                      ) and not fnc.__qualname__.startswith(
                          module.__name__ + "."
                      ):
                          pass  # print('not ours {} {}'.format(module, fnc))
                      else:
                          # we should not get here
                          setattr(
                              module,
                              fn,
                              _traced_call_static(prefix + fn, fnc),
                          )
              elif inspect.ismodule(module):
                  setattr(
                      module, fn, _traced_call_func(prefix + fn, fnc)
                  )
              else:
                  # we should not get here
                  setattr(
                      module, fn, _traced_call_func(prefix + fn, fnc)
                  )
  
file_path: clearml/clearml/debugging/trace.py
imports: import os
  import sys
  import threading
  import inspect
  import time
  import zipfile
label_desc: Use image node_id 8 for calling a global function with example usage: _patch_module(module, prefix, basepath, basemodule, exclude_prefixes, only_prefix) without return types