redirection.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:cauldron 作者: sernst 项目源码 文件源码
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__)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号