Sending and receiving async over multiprocessing.Pipe() in Python
- by dcolish
I'm having some issues getting the Pipe.send to work in this code. What I would ultimately like to do is send and receive messages to and from the foreign process while its running in a fork. This is eventually going to be integrated into a pexpect loop for talking to interpreter processes.
`
from multiprocessing import Process, Pipe
def f(conn):
cmd = ''
if conn.poll():
cmd = conn.recv()
i = 1
i += 1
conn.send([42 + i, cmd, 'hello'])
if __name__ == '__main__':
parent_conn, child_conn = Pipe()
p = Process(target=f, args=(child_conn,))
p.start()
from pdb import set_trace; set_trace()
while parent_conn.poll():
print parent_conn.recv() # prints "[42, None, 'hello']"
parent_conn.send('OHHAI')
p.join()
`