Created
June 7, 2020 18:56
-
-
Save VanDavv/7c3cd1e15c4067b76638b04187bce61a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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