import logging
import multiprocessing
import time
logging.basicConfig(level=logging.DEBUG, format='%(processName)s: %(message)s')
def worker1(i):
logging.debug('start')
time.sleep(5)
logging.debug('end')
return i * 2
if __name__ == '__main__':
with multiprocessing.Pool(3) as p:
r = p.map(worker1, [100, 200])
logging.debug('excuted map')
logging.debug(r)
r = p.map_async(worker1, [100, 200])
logging.debug('excuted map_async')
logging.debug(r.get())
r = p.imap(worker1, [100, 200])
logging.debug('excuted imap')
logging.debug([i for i in r])
#p1 = p.apply_async(worker1, (100,)) #非同期なので値が返ってくるのを待たずに次に進む
#p2 = p.apply_async(worker1, (100,))
#logging.debug('excuted')
#logging.debug(p1.get())
#logging.debug(p2.get())