buf = []
while True:
    line = infile.readline()
if not line:
    break
buf.append(line)
if line.endswith('.\n'):
    print('Decoding', buf)
print(pickle.loads(''.join(buf)))
buf = []
Reading multiple Python pickled data at once, buffering and newlines?