Why does pool run the entire file multiple times?

后端 未结 4 1191
南方客
南方客 2020-12-19 06:46

I\'m trying to understand the output from this Python 2.7.5 example script:

import time
from multiprocessing import Pool

print(time.strftime(\'%Y-%m-%d %H:%         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-19 07:40

    Multiprocessing needs to import your script in each subprocess in order to use the go() function. When your script is imported, it prints the date. If you only want something to run in the main script, put it in the if __name__ == '__main__' block.

提交回复
热议问题