Why does pool run the entire file multiple times?

后端 未结 4 1184
南方客
南方客 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条回答
  •  萌比男神i
    2020-12-19 07:32

    The modification presented below won't print those lines multiple time.

    import time
    
    from multiprocessing import Pool
    
    def main():
      if __name__ == '__main__':
      print(time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time())))
      props2=[
            '170339',
            '170357',
            '170345',
            '170346',
            '171232',
            '170363',
            ]
    
      pool = Pool(processes=3)
      pool.map(go, props2)
    
      print(time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time())))
    
    def go(x):
      print(x)
    
    main()
    

提交回复
热议问题