在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  Python/ python中的進程

python中的進程

為什么multiprocessing的Process類必須要在if __name__="__main__"下調(diào)用,否則報錯?這種情況只在Windows中存在,無法理解網(wǎng)上的解釋

Since Windows has no fork, the multiprocessing module starts a new Python process and imports the calling module. If Process() gets called upon import, then this sets off an infinite succession of new processes (or until your machine runs out of resources). This is the reason for hiding calls to Process() insideif name == "__main__"since statements inside this if-statement will not get called upon import.
鏈接:https://www.zhihu.com/questio...
回答
編輯回答
悶騷型

這段網(wǎng)文只道出因為windows沒有fork, 然後又說windows python 用multiprocessing module 實現(xiàn)多進程。。。,實現(xiàn)了process() 的代碼如果被import而沒有ifXxxxxxxx的話會有死循環(huán)。
其實fork 是unix和linix 實現(xiàn)多進程的方式,跟windows有分別,樓主先去理解fork 吧, 抱歉,我不懂,只是提出個方向

2018年5月3日 04:25