I have a really simple code below. #! / USR / bin / python from multiprocessor import pool import time
def worker(job): if job in range(25,30): time.sleep(10) print "job:%s" %job return (job) pool = Pool(processes=10) result = [] for job in range(1, 1000): result.append(pool.apply_async(worker(job))) pool.close() pool.join()
As you can see, I have a worker to handle 1000 jobs using multiprocessing. If the task is 25-30, the worker will sleep 10 seconds. This is an attempt to simulate the task of spending time and resources.
When I run the above code, the output looks like below. From task 25. The whole process works as a sequential process. Since every 10 seconds there is a result after task 24. Until task 30 is completed.
But why? Should a multiprocessor process work simultaneously?
[ root@localhost tmp]
source share