我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用atexit._exithandlers()。
def setUp(self): s = StringIO.StringIO() self.save_stdout = sys.stdout self.save_stderr = sys.stderr sys.stdout = sys.stderr = self.subst_io = s self.save_handlers = atexit._exithandlers atexit._exithandlers = []
def tearDown(self): sys.stdout = self.save_stdout sys.stderr = self.save_stderr atexit._exithandlers = self.save_handlers
def delete_logs(): if hasattr(atexit, "_clear"): atexit._clear() elif hasattr(atexit, "_exithandlers"): atexit._exithandlers[:] = [] # stop the logging module's exit handler for suffix in Logger.LEVELS: filename = "unit_tests.{0}_log".format(suffix) if os.path.exists(filename): handlers = logging.getLogger("unit_tests." + suffix).handlers if handlers and handlers[0].stream: handlers[0].stream.close() os.remove(filename)