1def read_file(path, block_size=1024):
2 with open(path, 'rb') as f:
3 while True:
4 piece = f.read(block_size)
5 if piece:
6 yield piece
7 else:
8 return
9
10for piece in read_file(path):
11 process_piece(piece)
12