def restore_profiler():
"""If a typechecking profiler is active, e.g. created by
pytypes.set_global_typechecked_profiler(), such a profiler
must be restored whenever a TypeCheckError is caught.
The call must stem from the thread that raised the error.
Otherwise the typechecking profiler is implicitly disabled.
Alternatively one can turn pytypes into warning mode. In that
mode no calls to this function are required (unless one uses
filterwarnings("error") or likewise).
"""
idn = threading.current_thread().ident
if not sys.getprofile() is None:
warn("restore_profiler: Current profile is not None!")
if not idn in _saved_profilers:
warn("restore_profiler: No saved profiler for calling thread!")
else:
sys.setprofile(_saved_profilers[idn])
del _saved_profilers[idn]
评论列表
文章目录