# your code goes here
from multiprocessing import Pool
import os, time, random
def long_time_task(name):
print('run task %s (%s)..' % (name, os.getpid()))
start=time.time()
time.sleep(random.random()*3)
end=time.time()
print('task %s runs %0.2f seconds.' % (name, (end-start)))
if __name__=='__main__':
print('parent process %s' % os.getpid())
p=Pool(4)
for i in range(5):
p.apply_async(long_time_task, args=(i,))
print('waiting for all subprocesses done..')
p.close()
p.join()
print('all subprocesses done')
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCmZyb20gbXVsdGlwcm9jZXNzaW5nIGltcG9ydCBQb29sCmltcG9ydCBvcywgdGltZSwgcmFuZG9tCgpkZWYgbG9uZ190aW1lX3Rhc2sobmFtZSk6CglwcmludCgncnVuIHRhc2sgJXMgKCVzKS4uJyAlIChuYW1lLCBvcy5nZXRwaWQoKSkpCglzdGFydD10aW1lLnRpbWUoKQoJdGltZS5zbGVlcChyYW5kb20ucmFuZG9tKCkqMykKCWVuZD10aW1lLnRpbWUoKQoJcHJpbnQoJ3Rhc2sgJXMgcnVucyAlMC4yZiBzZWNvbmRzLicgJSAobmFtZSwgKGVuZC1zdGFydCkpKQoKaWYgX19uYW1lX189PSdfX21haW5fXyc6CglwcmludCgncGFyZW50IHByb2Nlc3MgJXMnICUgb3MuZ2V0cGlkKCkpCglwPVBvb2woNCkKCWZvciBpIGluIHJhbmdlKDUpOgoJCXAuYXBwbHlfYXN5bmMobG9uZ190aW1lX3Rhc2ssIGFyZ3M9KGksKSkKCXByaW50KCd3YWl0aW5nIGZvciBhbGwgc3VicHJvY2Vzc2VzIGRvbmUuLicpCglwLmNsb3NlKCkKCXAuam9pbigpCglwcmludCgnYWxsIHN1YnByb2Nlc3NlcyBkb25lJyk=