我想读取一个 4 行 4 行的文件(它是一个带有 DNA 序列的 fastq 文件)。
当我一行一行或一行一行地读取文件时,没有问题,但是当我一次读取 3 或 4 行时,我的代码崩溃了(内核似乎在 jupyter notebook 上死了)。(取消注释最后一部分,或 4 中的任何 3 部分getline()
。
我尝试使用 char (char**) 的双数组来存储行,但存在相同的问题。
知道是什么原因吗?
使用 Python 3.7.3、Cython 0.29,更新了所有其他库。正在读取的文件大约为 1.3GB,机器有 8GB,ubuntu 16.04。代码改编自https://gist.github.com/pydemo/0b85bd5d1c017f6873422e02aeb9618a
%%cython
from libc.stdio cimport FILE, fopen, fclose, getline
def fastq_reader(early_stop=10):
cdef const char* fname = b'/path/to/file'
cdef FILE* cfile
cfile = fopen(fname, "rb")
cdef:
char * line_0 = NULL
char * line_1 = NULL
char * line_2 = NULL
char * line_3 …
Run Code Online (Sandbox Code Playgroud)