本文整理匯總了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()