Reputation: 705
I have a very simple multiprocessing example that I found online (shown below). For some reason, when I execute it in Spyder, it doesn't print anything out at all. It doesn't hang either. I'm using Python 3.x. Does anyone have any idea why?
from multiprocessing import Process
def print_func(continent='Asia'):
print('The name of continent is : ', continent)
if __name__ == "__main__": # confirms that the code is under main function
names = ['America', 'Europe', 'Africa']
procs = []
proc = Process(target=print_func) # instantiating without any argument
procs.append(proc)
proc.start()
# instantiating process with arguments
for name in names:
# print(name)
proc = Process(target=print_func, args=(name,))
procs.append(proc)
proc.start()
# complete the processes
for proc in procs:
proc.join()
Upvotes: 0
Views: 51
Reputation: 3286
When you in threads or other process you will not get its stdout, so if you want to log you better use python logging documentation link: https://docs.python.org/3/library/logging.html
you can also check this for more solutions https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/
Upvotes: 1