title: How can I send a byte-object over a pipe in python?
body: <p>I am trying to send a numpy array over stdout from one process to another.</p>
  
  <p>Sending it over the pipe requires me to convert it to a string.
  On the other side, I receive a byte object. This byte object now has the original byte string encapsulated.</p>
  
  <p>I find it now impossible to restore the original byte object as a byte object.
  If I decode the byte object, I receive a string which is incompatible with all the restoring functions I tried (np.frombuffer, pickle.loads).</p>
  
  <p>server.py</p>
  
  <pre><code>import subprocess
  import numpy as np
  p = subprocess.Popen(['python3', 'writer.py'], stdout=subprocess.PIPE)
  
  while 1:
      tmp = p.stdout.readline()    
      # doesn't fail but wrong size
      array = np.frombuffer(tmp, dtype=np.uint8)
      tmp = bytes.decode(tmp)
      # fails because byte object is necessary
      array = np.frombuffer(tmp, dtype=np.uint8)
      array = array.reshape([1, 3, 5, 5, 1])
      print(array.shape)
  </code></pre>
  
  <p>writer.py</p>
  
  <pre><code>import numpy as np
  import sys
  while 1:
      array = np.zeros([1, 3, 5, 5, 1], dtype=np.int8)
      string = array.tobytes()
      sys.stdout.write(str(string))
      sys.stdout.flush()
  </code></pre>
  
  <p>Is there anyway to convert the string into a byteobject, without encoding it? 
  How else could this work?
  I want to use pipes instead of shared memory as proposed in some other solutions to keep it more simple. Furthermore, I need it to be parallel but blocking, so Pipes seemed ideal to me.</p>
  
  <p>Thanks</p>