def restore_default_configuration():
"""
Restores the sys.stdout and the sys.stderr buffer streams to their default
values without regard to what step has currently overridden their values.
This is useful during cleanup outside of the running execution block
"""
def restore(target, default_value):
if target == default_value:
return default_value
if not isinstance(target, RedirectBuffer):
return target
try:
target.active = False
target.close()
except Exception:
pass
return default_value
sys.stdout = restore(sys.stdout, sys.__stdout__)
sys.stderr = restore(sys.stderr, sys.__stderr__)
评论列表
文章目录