1

I need a stream in Python that is writing stuff. But while it is writing it, a threaded method should read from it, until it gets closed (EOF).

So far I can only create a stream with stream = io.BinaryIO('binarystart') and then stream.seek(0, 1) to begining of the stream to read it. But then I cannot append binary strings to the end of the stream. Because the main process shares the same stream (therefor also the same cursor and cursor position) with the threaded reader.

Any ideas to solve this?

max
  • 318
  • 1
  • 11
  • Add a lock so only one thread manipulates the stream at one time. This may require saving and restoring the cursor state of the stream by each thread so they don't mess each others processing up. – martineau May 29 '15 at 13:47
  • First you mention "threaded" then you mention "main process" so I'm not sure if the reading and writing are happening in different threads or different processes. Might want to edit your question to clarify that. If they are different processes, a pipe is probably what you want, but given your question, you probably mean threads?? – Waylan May 29 '15 at 15:59
  • This [question](http://stackoverflow.com/q/375427/) has lots of useful info. Granted, it doesn't specifically pertain to `io.BinaryIO` but is should get you pointed in the right direction. – Waylan May 29 '15 at 16:06

0 Answers0