Here is my multiprocessing code.
from multiprocessing import Process
def print_func(continent = 'Asia'):
print('The name of continent is: ',continent)
if __name__ == "__main__":
names = ['America','Russia','Africa']
procs = []
proc = Process(target = print_func)
procs.append(proc)
proc.start()
for name in names:
proc = Process(target = print_func,args =(name,))
procs.append(proc)
proc.start()
for proc in procs:
proc.join()
But it shows no output! What am I doing wrong?
I want output like this:
The name of continent is: Asia
The name of continent is: America
The name of continent is: Russia
The name of continent is: Africa
As described in this answer and this bug report, this is a design limitation of IDLE. Since IDLE connects only to the started process and not its children, it does not catch the output.
Run the code in another Python IDE (IDLE is chiefly aimed at beginners), or just run the program without an IDE, i.e. (assuming your program file is called multiprint.py
) with
python multiprint.py