我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用atexit._clear()。
def setUp(self): self.save_stdout = sys.stdout self.save_stderr = sys.stderr self.stream = io.StringIO() sys.stdout = sys.stderr = self.stream atexit._clear()
def tearDown(self): sys.stdout = self.save_stdout sys.stderr = self.save_stderr atexit._clear()
def test_clear(self): a = [0] def inc(): a[0] += 1 atexit.register(inc) atexit._clear() atexit._run_exitfuncs() self.assertEqual(a[0], 0)
def exit(): """Exit subprocess, possibly after first clearing exit functions. If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any functions registered with atexit will be removed before exiting. (VPython support) """ if no_exitfunc: import atexit atexit._clear() sys.exit(0)
def exit(): """Exit subprocess, possibly after first clearing exit functions. If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any functions registered with atexit will be removed before exiting. (VPython support) """ if no_exitfunc: import atexit atexit._clear() capture_warnings(False) sys.exit(0)
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)