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