Skip to content

Instantly share code, notes, and snippets.

@VanDavv
Created June 7, 2020 18:56
Show Gist options
  • Save VanDavv/7c3cd1e15c4067b76638b04187bce61a to your computer and use it in GitHub Desktop.
Save VanDavv/7c3cd1e15c4067b76638b04187bce61a to your computer and use it in GitHub Desktop.
from multiprocessing import Pipe, Process
def _thread_fun(pipe: Pipe):
while True:
print('WAITING')
val = pipe.recv()
if val == 'FINISH':
print('FINISHING')
break
pipe.send(val * 10)
print('DONE')
print('OUTSIDE')
if __name__ == '__main__':
myPipe, subPipe = Pipe()
p = Process(target=_thread_fun, args=(subPipe, ))
p.start()
myPipe.send(1)
while not (status := myPipe.poll()):
print(status)
print(status)
print(myPipe.recv())
myPipe.send(2)
print(myPipe.recv())
myPipe.send(3)
print(myPipe.recv())
myPipe.send('FINISH')
p.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment