with gzip.open('/path/to/file/myfile.gz') as f:
    for i, line in enumerate(f):
        fastload_fifo.write(line)
print('Number of lines', i + 1)
os.unlink(fifo_path)
Pythonic way to send contents of a file to a pipe and count # lines in a single step