Debug

Some generic debugging utilities.

Debug.auto_exclude_all_new_threads(func)[source]
Parameters:func (T) –
Returns:func wrapped
Return type:T
Debug.dump_all_thread_tracebacks(exclude_thread_ids=None, exclude_self=False)[source]
Parameters:
  • exclude_thread_ids (set[int]) –
  • exclude_self (bool) –
Debug.setup_warn_with_traceback()[source]

Installs some hook for warnings.showwarning.

Debug.init_better_exchook()[source]

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

Debug.format_signum(signum)[source]
Parameters:signum (int) –
Returns:string “signum (signame)”
Return type:str
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
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

Debug.install_native_signal_handler()[source]

Installs some own custom C signal handler.

Debug.install_lib_sig_segfault()[source]

Installs libSegFault (common on Unix/Linux).

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.
Debug.init_ipython_kernel(*args, **kwargs)[source]
Parameters:
  • args
  • kwargs
Returns:

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.

Debug.debug_shell(user_ns=None, user_global_ns=None, exit_afterwards=True)[source]

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

Parameters:
  • user_ns (dict[str]|None) –
  • user_global_ns (dict[str]|None) –
  • exit_afterwards (bool) – will do sys.exit(1) at the end