xopen.py 文件源码

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

项目:grocsvs 作者: grocsvs 项目源码 文件源码
def __init__(self, path, mode='w'):
        self.outfile = open(path, mode)
        self.devnull = open(os.devnull, 'w')
        self.closed = False

        # Setting close_fds to True in the Popen arguments is necessary due to
        # <http://bugs.python.org/issue12786>.
        kwargs = dict(stdin=PIPE, stdout=self.outfile, stderr=self.devnull, close_fds=True)
        try:
            self.process = Popen(['pigz'], **kwargs)
            self.program = 'pigz'
        except OSError as e:
            # binary not found, try regular gzip
            try:
                self.process = Popen(['gzip'], **kwargs)
                self.program = 'gzip'
            except (IOError, OSError) as e:
                self.outfile.close()
                self.devnull.close()
                raise
        except IOError as e:
            self.outfile.close()
            self.devnull.close()
            raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号