0

from david beazley paper(https://www.dabeaz.com/usenix2009/concurrent/Concurrent.pdf, pg62), i am trying to run codes :

# channel.py
import pickle
class Channel(object):
 def __init__(self,out_f,in_f):
      self.out_f = out_f
      self.in_f = in_f
 def send(self,item):
     pickle.dump(item,self.out_f)
     self.out_f.flush()
 def recv(self):
     return pickle.load(self.in_f)
# child.py
import channel
import sys
ch = channel.Channel(sys.stdout,sys.stdin)
while True:
    item = ch.recv()
    ch.send(("child",item))

# parent.py
import channel
import subprocess
p = subprocess.Popen(['python','child.py'],
                     stdin=subprocess.PIPE,
                    stdout=subprocess.PIPE)
ch = channel.Channel(p.stdin,p.stdout)

• Using the child worker

ch.send("Hello World")

Hello World

When I try this code, I got this error

Traceback (most recent call last):
  File "child.py", line 6, in <module>
    item = ch.recv()
  File "C:\Users\bluesky\backtest\channel.py", line 16, in recv
    return pickle.load(self.in_f)
TypeError: a bytes-like object is required, not 'str'

what i am trying to get is that sending my data to child and get back processed data to parent process, is there any way to fix it

AlanS
  • 1
  • 1
  • Does this answer your question? [TypeError: a bytes-like object is required, not 'str' when writing to a file in Python3](https://stackoverflow.com/questions/33054527/typeerror-a-bytes-like-object-is-required-not-str-when-writing-to-a-file-in) – Mahdi mehrabi Jul 16 '21 at 17:44
  • tried already b'' version, but not worked – AlanS Jul 16 '21 at 18:55

0 Answers0