Skip to content

Instantly share code, notes, and snippets.

@jsrimr
Created October 20, 2020 08:24
Show Gist options
  • Save jsrimr/0f6d4089c5b196e4571c63ae69e04704 to your computer and use it in GitHub Desktop.
Save jsrimr/0f6d4089c5b196e4571c63ae69e04704 to your computer and use it in GitHub Desktop.
multiprocess시에 pipe를 만들면 프로세스들은 각자 pipe에 대고 listen, speak할 수 있다. 한쪽의 process가 pipe의 listen쪽이나 speak쪽을 닫더라도 다른 process는 여전히 이 파이프를 통해 listen, speak 할 수 있다
from multiprocessing import Process, Pipe
import time
remotes, work_remotes = zip(*[Pipe() for _ in range(10)])
def worker(remote, parent_remote):
parent_remote.close()
print(f"closed {id(parent_remote)}, {time.time()}")
# print(f"In worker : {id(remotes[0])} is closed. {remotes[0].closed}")
print(f"{id(remotes[0])}")
ps = [Process(target=worker, args=(work_remote, remote)) for (work_remote, remote) in zip(work_remotes, remotes)]
for p in ps:
p.daemon=True
p.start()
time.sleep(3)
print(f"{id(remotes[0])} is closed. {remotes[0].closed}, {time.time()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment