Created
January 13, 2020 20:01
-
-
Save DuaneNielsen/b2214b356d9f374b9728e82dd54b340e to your computer and use it in GitHub Desktop.
Multiprocessing in python
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
import multiprocessing as mp | |
import os | |
import numpy as np | |
import multiprocessing.spawn | |
def info(title): | |
print(title) | |
print('module name:', __name__) | |
print('parent process:', os.getppid()) | |
print('process id:', os.getpid()) | |
def hello(args): | |
print(args) | |
info('hello') | |
return args | |
if __name__ == '__main__': | |
mp.set_start_method('spawn') | |
array = np.random.rand(12) | |
policy = [{'one': x, 'two': array} for x in range(10)] | |
#policy = np.split(x, 10) | |
with mp.Pool(processes=10) as pool: | |
results = pool.map(hello, policy) | |
print(results) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment