程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

10、 Python learning notes - process - multi process

編輯:Python
# Create multi process demo code
""" Format
Process(target=Foo, args=("arg1", agg2, ....))
1、target Is the task to be executed by this thread
2、args It's the parameters that are passed , It's a tuple , The content can be one or more , must ‘,’ ending
3、start function ,join Blocking the main process (join The main process will not continue until the process ends ), See ‘ Process start and join’
4、Foo There is sleep, In case of serial, each output interval 2s, Parallel will be in sleep 2 Print together in seconds , Description is parallel
"""
from multiprocessing import Process
import time
def foo(n):
time.sleep(2)
print(n, time.ctime())
if __name__ == '__main__':
p_list = []
for i in range(1, 4):
p = Process(target=foo, args=("i",))
p_list.append(p)
p.start()
for p in p_list:
p.join()
print('end')

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved