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
评论列表
文章目录