Created
February 11, 2019 11:57
-
-
Save njsaunders/6bcc8f4d5eafd5665fdb7502771022d0 to your computer and use it in GitHub Desktop.
lambda_multiprocessing
This file contains 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 Process, Pipe | |
def add_two(x, conn): | |
conn.send([x+2]) | |
conn.close() | |
processes = [] | |
parent_connections = [] | |
xs = [1,2,3,4,5] | |
for x in xs: | |
parent_conn, child_conn = Pipe() | |
parent_connections.append(parent_conn) | |
process = Process(target=add_two, args=(x, child_conn,)) | |
processes.append(process) | |
process.start() | |
for process in processes: | |
process.join() | |
results = [p.recv()[0] for p in parent_connections] | |
print(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment