Multiprocessing a python script

264 Views Asked by At

I learnt about the multiprocessing tool in python: https://docs.python.org/2/library/multiprocessing.html.

Say I have a python program which is complicated and fleshed out, but it does not use up all my cores when running. So it uses 100% of one core and takes forever to complete. It is hard for me to go into the program's code and figure out how to split up the processes manually, simply cause the program is too complicated.

Is it possible to write a simple python script that enables multiprocessing on any python program I specify? To be exact, I want something as simple as this:

from multiprocessing import Process

Process(myprogram.py)

If not, is there a next-best method?

1

There are 1 best solutions below

0
On BEST ANSWER

After discussion, the straight answer is:

No.

Simply because multi-processing is not some magical trick that automatically offloads the burden on one processor to another. The developer needs to know how a program should split up a task, and specify that each task should take up a new process.

So ultimately, you have to be in control of your code in order to produce proper and efficient multi-processing.