python较为安全的关闭一个流的写法

阅读python的logging模块源码,这样关闭一个流

stream = self.stream
self.stream = None
if hasattr(stream, "close"):
    stream.close()


你可能感兴趣的:(python)