def _pickle_function(func, **kwargs): import Logging Logging.log("Error, not supported to pickle functions!") Logging.log(func.__name__, func.__qualname__) import better_exchook better_exchook.print_tb(None) raise Exception("no function pickling possible")
def dumpAllThreadTracebacks(exclude_thread_ids=set()): import better_exchook import threading if hasattr(sys, "_current_frames"): print("") threads = {t.ident: t for t in threading.enumerate()} for tid, stack in sys._current_frames().items(): if tid in exclude_thread_ids: continue # This is a bug in earlier Python versions. # http://bugs.python.org/issue17094 # Note that this leaves out all threads not created via the threading module. if tid not in threads: continue tags = [] thread = threads.get(tid) if thread: assert isinstance(thread, threading.Thread) if thread is threading.currentThread(): tags += ["current"] if isinstance(thread, threading._MainThread): tags += ["main"] tags += [str(thread)] else: tags += ["unknown with id %i" % tid] print("Thread %s:" % ", ".join(tags)) if tid in global_exclude_thread_ids: print("(Auto-ignored traceback.)") else: better_exchook.print_tb(stack, file=sys.stdout) print("") print("That were all threads.") else: print( "Does not have sys._current_frames, cannot get thread tracebacks.")
def warn_with_traceback(message, category, filename, lineno, file=None, line=None): log = file if hasattr(file, 'write') else sys.stderr log.write( warnings.formatwarning(message, category, filename, lineno, line)) better_exchook.print_tb(sys._getframe(), file=log)
def debugWarn(msg): print("Warning:", msg) import sys if not hasattr(sys, "_getframe"): print("Warning: debugWarn: no sys._getframe") return f = sys._getframe() if not f: print("Warning: debugWarn: no frame") f = f.f_back if not f: print("Warning: debugWarn: no previous frame") better_exchook.print_tb(f)
def warn_with_traceback(message, category, filename, lineno, file=None, line=None): """ :param message: :param category: :param filename: :param lineno: :param file: :param line: """ log = file if hasattr(file, 'write') else sys.stderr log.write(warnings.formatwarning(message, category, filename, lineno, line)) # noinspection PyProtectedMember better_exchook.print_tb(sys._getframe(), file=log)
def dump_all_thread_tracebacks(exclude_thread_ids=None, exclude_self=False): """ :param set[int] exclude_thread_ids: :param bool exclude_self: """ if exclude_thread_ids is None: exclude_thread_ids = set() import better_exchook import threading if exclude_self: exclude_thread_ids = set( list(exclude_thread_ids) + [threading.current_thread().ident]) if hasattr(sys, "_current_frames"): print("") threads = {t.ident: t for t in threading.enumerate()} # noinspection PyProtectedMember for tid, stack in sorted(sys._current_frames().items()): # This is a bug in earlier Python versions. # http://bugs.python.org/issue17094 # Note that this leaves out all threads not created via the threading module. if tid not in threads: continue tags = [] thread_ = threads.get(tid) if thread_: assert isinstance(thread_, threading.Thread) if thread_ is threading.currentThread(): tags += ["current"] # noinspection PyUnresolvedReferences,PyProtectedMember if isinstance(thread_, threading._MainThread): tags += ["main"] tags += [str(thread_)] else: tags += ["unknown with id %i" % tid] print("Thread %s:" % ", ".join(tags)) if tid in global_exclude_thread_ids: print("(Auto-ignored traceback.)") elif tid in exclude_thread_ids: print("(Excluded thread.)") else: better_exchook.print_tb(stack, file=sys.stdout) print("") print("That were all threads.") else: print( "Does not have sys._current_frames, cannot get thread tracebacks.")
def dump_all_thread_tracebacks(exclude_thread_ids=None, exclude_self=False): """ :param set[int] exclude_thread_ids: :param bool exclude_self: """ if exclude_thread_ids is None: exclude_thread_ids = set() import better_exchook import threading if exclude_self: exclude_thread_ids = set(list(exclude_thread_ids) + [threading.current_thread().ident]) if hasattr(sys, "_current_frames"): print("") threads = {t.ident: t for t in threading.enumerate()} # noinspection PyProtectedMember for tid, stack in sorted(sys._current_frames().items()): # This is a bug in earlier Python versions. # http://bugs.python.org/issue17094 # Note that this leaves out all threads not created via the threading module. if tid not in threads: continue tags = [] thread_ = threads.get(tid) if thread_: assert isinstance(thread_, threading.Thread) if thread_ is threading.currentThread(): tags += ["current"] # noinspection PyUnresolvedReferences,PyProtectedMember if isinstance(thread_, threading._MainThread): tags += ["main"] tags += [str(thread_)] else: tags += ["unknown with id %i" % tid] print("Thread %s:" % ", ".join(tags)) if tid in global_exclude_thread_ids: print("(Auto-ignored traceback.)") elif tid in exclude_thread_ids: print("(Excluded thread.)") else: better_exchook.print_tb(stack, file=sys.stdout) print("") print("That were all threads.") else: print("Does not have sys._current_frames, cannot get thread tracebacks.")
def signal_handler(signal, frame): print("\nSIGINT at:") better_exchook.print_tb(tb=frame, file=sys.stdout) print("") # It's likely that SIGINT was caused by Util.interrupt_main(). # We might have a stacktrace from there. if getattr(sys, "exited_frame", None) is not None: print("interrupt_main via:") better_exchook.print_tb(tb=sys.exited_frame, file=sys.stdout) print("") sys.exited_frame = None # Normal exception instead so that Nose will catch it. raise Exception("Got SIGINT!") else: print("\nno sys.exited_frame\n") # Normal SIGINT. Normal Nose exit. if old_action: old_action() else: raise KeyboardInterrupt
def signal_handler(signal, frame): print "\nSIGINT at:" better_exchook.print_tb(tb=frame, file=sys.stdout) print "" # It's likely that SIGINT was caused by Util.interrupt_main(). # We might have a stacktrace from there. if getattr(sys, "exited_frame", None) is not None: print "interrupt_main via:" better_exchook.print_tb(tb=sys.exited_frame, file=sys.stdout) print "" sys.exited_frame = None # Normal exception instead so that Nose will catch it. raise Exception("Got SIGINT!") else: print "\nno sys.exited_frame\n" # Normal SIGINT. Normal Nose exit. if old_action: old_action() else: raise KeyboardInterrupt
def dumpAllThreadTracebacks(exclude_thread_ids=set()): import better_exchook import threading if hasattr(sys, "_current_frames"): print "" threads = {t.ident: t for t in threading.enumerate()} for tid, stack in sys._current_frames().items(): if tid in exclude_thread_ids: continue # This is a bug in earlier Python versions. # http://bugs.python.org/issue17094 # Note that this leaves out all threads not created via the threading module. if tid not in threads: continue print "Thread %s:" % threads.get(tid, "unnamed with id %i" % tid) if tid in global_exclude_thread_ids: print "(Auto-ignored traceback.)" else: better_exchook.print_tb(stack) print "" else: print "Does not have sys._current_frames, cannot get thread tracebacks."
def dumpAllThreadTracebacks(exclude_thread_ids=set()): import better_exchook import threading if hasattr(sys, "_current_frames"): print("") threads = {t.ident: t for t in threading.enumerate()} for tid, stack in sys._current_frames().items(): if tid in exclude_thread_ids: continue # This is a bug in earlier Python versions. # http://bugs.python.org/issue17094 # Note that this leaves out all threads not created via the threading module. if tid not in threads: continue print("Thread %s:" % threads.get(tid, "unnamed with id %i" % tid)) if tid in global_exclude_thread_ids: print("(Auto-ignored traceback.)") else: better_exchook.print_tb(stack) print("") else: print( "Does not have sys._current_frames, cannot get thread tracebacks.")
def _setup(): """ This does the setup, such that all the modules become available in the `returnn` package. It does not import all the modules now, but instead provides them lazily. """ import os import sys for fn in sorted(os.listdir(_my_dir)): if os.path.isdir("%s/%s" % (_my_dir, fn)) and os.path.exists( "%s/%s/__init__.py" % (_my_dir, fn)): mod_name = fn else: mod_name, ext = os.path.splitext(fn) if ext != ".py": continue if mod_name.startswith("__"): continue if mod_name in sys.modules: # This is difficult to get right. # We will just use the existing module. Print a warning. if int(os.environ.get("DEBUG_RETURNN_IMPORT", "0")): print( "RETURNN import warning: module %r already imported as an absolute module" % mod_name) import better_exchook better_exchook.print_tb(None) mod = sys.modules[mod_name] else: mod = _LazyLoader(mod_name) globals( )[mod_name] = mod # make available as `returnn.<mod_name>` (attribute) sys.modules[mod_name] = mod # absolute import sys.modules["%s.%s" % (__package__, mod_name )] = mod # `returnn.<mod_name>` as relative import
def sigusr1_handler(sig, frame): print "--- SIGUSR1 handler" better_exchook.print_tb(tb=frame)