我正在使用pythons bz2模块生成(并压缩)一个大型 jsonl 文件(bzip2 压缩 17GB)。
但是,当我后来尝试使用 pbzip2 对其进行解压缩时,它似乎只使用一个CPU 内核进行解压缩,这很慢。
当我用 pbzip2 压缩它时,它可以利用多个核心进行解压缩。有没有办法在 python 中以 pbzip2 兼容的格式压缩?
import bz2,sys
from Queue import Empty
#...
compressor = bz2.BZ2Compressor(9)
f = open(path, 'a')
try:
while 1:
m = queue.get(True, 1*60)
f.write(compressor.compress(m+"\n"))
except Empty, e:
pass
except Exception as e:
traceback.print_exc()
finally:
sys.stderr.write("flushing")
f.write(compressor.flush())
f.close()