本文整理汇总了Python中sys.is_finalizing方法的典型用法代码示例。如果您正苦于以下问题:Python sys.is_finalizing方法的具体用法?Python sys.is_finalizing怎么用?Python sys.is_finalizing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.is_finalizing方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_finalizing
# 需要导入模块: import sys [as 别名]
# 或者: from sys import is_finalizing [as 别名]
def test_is_finalizing(self):
self.assertIs(sys.is_finalizing(), False)
# Don't use the atexit module because _Py_Finalizing is only set
# after calling atexit callbacks
code = """if 1:
import sys
class AtExit:
is_finalizing = sys.is_finalizing
print = print
def __del__(self):
self.print(self.is_finalizing(), flush=True)
# Keep a reference in the __main__ module namespace, so the
# AtExit destructor will be called at Python exit
ref = AtExit()
"""
rc, stdout, stderr = assert_python_ok('-c', code)
self.assertEqual(stdout.rstrip(), b'True')
示例2: _get_emulated_is_finalizing
# 需要导入模块: import sys [as 别名]
# 或者: from sys import is_finalizing [as 别名]
def _get_emulated_is_finalizing() -> Callable[[], bool]:
L = [] # type: List[None]
atexit.register(lambda: L.append(None))
def is_finalizing() -> bool:
# Not referencing any globals here
return L != []
return is_finalizing
示例3: _get_emulated_is_finalizing
# 需要导入模块: import sys [as 别名]
# 或者: from sys import is_finalizing [as 别名]
def _get_emulated_is_finalizing():
L = []
atexit.register(lambda: L.append(None))
def is_finalizing():
# Not referencing any globals here
return L != []
return is_finalizing
示例4: close
# 需要导入模块: import sys [as 别名]
# 或者: from sys import is_finalizing [as 别名]
def close(self):
super().close()
if not sys.is_finalizing():
for sig in list(self._signal_handlers):
self.remove_signal_handler(sig)
else:
if self._signal_handlers:
warnings.warn(f"Closing the loop {self!r} "
f"on interpreter shutdown "
f"stage, skipping signal handlers removal",
ResourceWarning,
source=self)
self._signal_handlers.clear()
示例5: __del__
# 需要导入模块: import sys [as 别名]
# 或者: from sys import is_finalizing [as 别名]
def __del__(self):
if (
not self.asynchronous
and hasattr(self, "_loop_runner")
and not sys.is_finalizing()
):
self.close()