search

Home  >  Q&A  >  body text

python3.x - Python用for line in read(file,'rb'):处理超大文件时,想用多线程,该如何分配合适的文件偏移?

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

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

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:04:32

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

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:04:32

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

    reply
    0
  • Cancelreply