Friday, 26 August 2016

Multiprocessing Pool

The scripts show how to make use of the mutiprocessing ability of Python to handle a batch of processes.

All CPUs of the computer running the scripts will be called at the same time. The job handler (thrd-m.py) see all CPUs available as a pool, it fetches jobs from a list stored in it. The jobs are 10 copies of a time killing work (long01.py) which generates the number pi from a series.
  1. Check the number of CPUs available.
  2. Define a multiprocessing pool.
  3. Fetch jobs from a list and submit them, one by one, to the pool.
  4. Wait for the completion of all jobs.

Source Code



Here is the job handler (thrd-m.py)


Here is the time killing process (long01.py)


A sample result of running thrd-m.py by a Core i5 is given below

No comments:

Post a Comment