python3.x - Python用for line in read(file,'rb'):处理超大文件时,想用多线程,该如何分配合适的文件偏移?
PHPz
PHPz 2017-04-18 10:02:32
0
2
440

文件大概有80个G大小,想用多线程,我知道可以用f.seek()去设置偏移,以达到从不同的位置开始读入的效果
可是应该如何给每个线程分配一个合适偏移?

with open(r'file.txt', 'rb') as f:
    for line in f:
        dosomething(line)
PHPz
PHPz

学习是最好的投资!

reply all(2)
Ty80

You can split large files now, and then multi-thread the split small files: http://www.jb51.net/article/5...

巴扎黑

Use the mmap module to read and write files like accessing memory.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template