returnn.util.debug

Some generic debugging utilities.

returnn.util.debug.auto_exclude_all_new_threads(func)[source]
Parameters:

func (T)

Returns:

func wrapped

Return type:

T

returnn.util.debug.dump_all_thread_tracebacks(exclude_thread_ids=None, exclude_self=False)[source]
Parameters:
  • exclude_thread_ids (set[int])

  • exclude_self (bool)

returnn.util.debug.setup_warn_with_traceback()[source]

Installs some hook for warnings.showwarning.

returnn.util.debug.init_better_exchook()[source]

Installs our own sys.excepthook, which uses better_exchook, but adds some special handling for the main thread.

returnn.util.debug.format_signum(signum)[source]
Parameters:

signum (int)

Returns:

string “signum (signame)”

Return type:

str

returnn.util.debug.signal_handler(signum, frame)[source]

Prints a message on stdout and dump all thread stacks.

Parameters:
  • signum (int) – e.g. signal.SIGUSR1

  • frame – ignored, will dump all threads

returnn.util.debug.install_signal_handler_if_default(signum, exceptions_are_fatal=False)[source]
Parameters:
  • signum (int) – e.g. signal.SIGUSR1

  • exceptions_are_fatal (bool) – if True, will reraise any exceptions. if False, will just print a message

Returns:

True iff no exception, False otherwise. not necessarily that we registered our own handler

Return type:

bool

returnn.util.debug.install_native_signal_handler(*, reraise_exceptions: bool = False)[source]

Installs some own custom C signal handler.

returnn.util.debug.install_lib_sig_segfault()[source]

Installs libSegFault (common on Unix/Linux).

returnn.util.debug.init_faulthandler(sigusr1_chain=False)[source]

Maybe installs signal handlers, SIGUSR1 and SIGUSR2 and others. If no signals handlers are installed yet for SIGUSR1/2, we try to install our own Python handler. This also tries to install the handler from the fauldhandler module, esp for SIGSEGV and others.

Parameters:

sigusr1_chain (bool) – whether the default SIGUSR1 handler should also be called.

returnn.util.debug.init_ipython_kernel(*args, **kwargs)[source]
Parameters:
  • args

  • kwargs

Returns:

returnn.util.debug.init_cuda_not_in_main_proc_check()[source]

Installs some hook to Theano which checks that CUDA is only used in the main proc.

returnn.util.debug.debug_shell(user_ns: Dict[str, Any] | None = None, user_global_ns: Dict[str, Any] | None = None, exit_afterwards: bool = True)[source]

Provides some interactive Python shell. Uses IPython if possible. Wraps to better_exchook.debug_shell.

Parameters:
  • user_ns

  • user_global_ns

  • exit_afterwards – will do sys.exit(1) at the end