Skip to content

Instantly share code, notes, and snippets.

@DuaneNielsen
Created January 13, 2020 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DuaneNielsen/b2214b356d9f374b9728e82dd54b340e to your computer and use it in GitHub Desktop.
Save DuaneNielsen/b2214b356d9f374b9728e82dd54b340e to your computer and use it in GitHub Desktop.
Multiprocessing in python
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