Python multiprocessing tips

参考链接:http://www.doughellmann.com/PyMOTW/multiprocessing/basics.html

One difference between the threading and multiprocessing examples is the extra protection for __main__ used in themultiprocessing examples. Due to the way the new processes are started, the child process needs to be able to import the script containing the target function. Wrapping the main part of the application in a check for __main__ ensures that it is not run recursively in each child as the module is imported. Another approach is to import the target function from a separate script.

 

具体可以看document中的叙述,总之必须添加如下代码才可以正常运行:

if __name__ == '__main__':

 

原文地址:https://www.cnblogs.com/kanone/p/2599528.html