创建一个多进程(multiprocessing.Process)
生活随笔
收集整理的這篇文章主要介紹了
创建一个多进程(multiprocessing.Process)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
進程是資源的集合,每個進程至少包含一個線程
import multiprocessing #導入進程模塊
import time, threading #導入線程
def thread_run():
print(threading.get_ident())
def run(name):
time.sleep(2)
print('hello', name)
t = threading.Thread(target=thread_run) #創建一個線程
t.start()
if __name__ == '__main__': '''
在進程中創建一個線程
'''
for i in range(10): #循環十次
p = multiprocessing.Process(target=run, args=(i, )) #在進程中添加線程
p.start()
import multiprocessing #導入進程模塊
import time, threading #導入線程
def thread_run():
print(threading.get_ident())
def run(name):
time.sleep(2)
print('hello', name)
t = threading.Thread(target=thread_run) #創建一個線程
t.start()
if __name__ == '__main__': '''
在進程中創建一個線程
'''
for i in range(10): #循環十次
p = multiprocessing.Process(target=run, args=(i, )) #在進程中添加線程
p.start()
轉載于:https://www.cnblogs.com/my-love-is-python/p/9164437.html
總結
以上是生活随笔為你收集整理的创建一个多进程(multiprocessing.Process)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vue.js 2.x笔记:表单绑定(3)
- 下一篇: 618 京东到家-小程序也狂欢