Python multiprocessing tips

Posted on 2012-07-19 16:25  Kanone  阅读(210)  评论(0编辑  收藏  举报

参考链接: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__':