To pipe data from one process to another as a stream in python we need to pickle the object and pass it to the pipe stream. In this example I've used Numpy arrays but this could be applied to any object that can be pickled in Python. This took far too long to get working and I could find little information online on how to put it all together so here it is. This code is Python 3 only, I've only run this on a Mac.
I've used binary as the stream rather than text purley becuase of effiencies. Numpy arrays can get huge! This means readline()
is not
going to work. Instead, I send a single control byte , 1, for data and 0 for stop. This could be extended to include other control operations.
I then send the length of the data as a 8 byte int, followed by the data itself.