1,我需要将一个.gz的压缩文件拆分成很多.gz文件;因为xopen运行速度较快,所以采用xopen来读取及写入.gz文件,经过测试采用xopen来读写压缩文件的速度的确要快很多。
出现的问题脚本通过命令行来运行(python XX.py)没有任何问题,但是将XX.py通过pyinstaller打包后就出现了以下问题:
1,通过xopen来写压缩文件,出现了 BrokenPipeError: [Errno 32] Broken pipe 的报错;
2,通过xopen来读压缩文件,发现读取到的是 代码中 输入参数报错的信息。
:
usage:
Usage: splitBarcode.exe >STDOUT
optional arguments:
show this help message and exit
–version show program’s version number and exit
ERROR: The parameters number is not correct!
尝试的解决方案尝试以下方案均无效:
1,查了网上,说的最多的关于多进程,pyinstaller 打包出问题的解决方案就是在
if __name__ == "main": 下添加: multiprocessing.freeze_support()
仍然不行
2,xopen官网(https://pypi.org/project/xopen/)上说 已经放弃对python3.6的支持(Dropped Python 3.6 support),所以将python升级为3.7。但是仍然不行。
可行的解决方案1,参照xopen官网(https://pypi.org/project/xopen/)上关于threads=0的说法和示例:
from xopen import xopen
with xopen(“file.txt.xz”, mode=“wb”, threads=0, compresslevel=3)
f.write(b"Hello")
将输出的代码中添加上threads=0,也就是由with xopen(“file.txt.xz”, mode=“wb”),改为
with xopen(“file.txt.xz”, mode=“wb”, threads=0, compresslevel=3),输出部分代码即可成功打包。
2,读压缩文件部分,也添加上threads=0,即可成功打包;
即由with xopen.xopen(fastqFile) as pf: 变为 with xopen.xopen(fastqFile, threads=0) as pf
总结在读和写的代码中添加threads=0,即由with xopen.xopen(fastqFile) as pf: 变为 with xopen.xopen(fastqFile, threads=0) as pf



