pilhoon / wiki_public

0 stars 0 forks source link

multiprocessing #22

Open pilhoon opened 3 years ago

pilhoon commented 3 years ago

simple example

import multiprocessing
from os import getpid

def worker(procnum):
    print('I am number %d in process %d' % (procnum, getpid()))
    return getpid()

if __name__ == '__main__':
    pool = multiprocessing.Pool(processes = 3)
    print(pool.map(worker, range(5)))

https://stackoverflow.com/a/28799109/766330

multiple arguments with Pool : Pool.starmap

just change map to starmap https://stackoverflow.com/a/5442981/766330

call a local function from pool

use multiprocess.pool.ThreadPool (same usage with Pool) https://stackoverflow.com/a/58897266/766330