日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 管道队列_Python多处理 – 管道与队列

發布時間:2024/3/26 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 管道队列_Python多处理 – 管道与队列 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

> A

Pipe()只能有兩個端點。

> A

Queue()可以有多個生產者和消費者。

什么時候使用它們

如果你需要兩點以上的溝通,使用Queue()。

如果你需要絕對的性能,Pipe()是快得多,因為Queue()是建立在Pipe()之上。

性能基準

讓我們假設您想生成兩個進程,并盡可能快地在它們之間發送消息。這些是在使用Pipe()和Queue()的類似測試之間的拖動比賽的計時結果…這是在運行Ubuntu 11.10和Python 2.7.2的ThinkpadT61。

FYI,我把JoinableQueue()的結果作為獎金;調用queue.task_done()時,JoinableQueue()用于處理任務,它甚至不知道特定任務,它只計算隊列中未完成的任務),因此queue.join()知道工作已完成。

此答案底部的每個代碼…

mpenning@mpenning-T61:~$ python multi_pipe.py

Sending 10000 numbers to Pipe() took 0.0369849205017 seconds

Sending 100000 numbers to Pipe() took 0.328398942947 seconds

Sending 1000000 numbers to Pipe() took 3.17266988754 seconds

mpenning@mpenning-T61:~$ python multi_queue.py

Sending 10000 numbers to Queue() took 0.105256080627 seconds

Sending 100000 numbers to Queue() took 0.980564117432 seconds

Sending 1000000 numbers to Queue() took 10.1611330509 seconds

mpnening@mpenning-T61:~$ python multi_joinablequeue.py

Sending 10000 numbers to JoinableQueue() took 0.172781944275 seconds

Sending 100000 numbers to JoinableQueue() took 1.5714070797 seconds

Sending 1000000 numbers to JoinableQueue() took 15.8527247906 seconds

mpenning@mpenning-T61:~$

總之,Pipe()大約比Queue()快三倍。甚至不要考慮JoinableQueue(),除非你真的必須有好處。

獎金材料2

多處理引入信息流中的細微變化,使調試困難,除非你知道一些快捷方式。例如,您可能有一個腳本在許多條件下通過字典編制索引時工作正常,但很少在某些輸入下失敗。

通常,當整個python進程崩潰時,我們得到失敗的線索;但是,如果多處理函數崩潰,您不會收到未經請求的崩潰回溯到控制臺。跟蹤未知的多處理崩潰是很困難的,沒有關于什么崩潰的過程的線索。

我發現跟蹤多處理崩潰信息的最簡單的方法是將整個多處理函數包裝在try / except中,并使用traceback.print_exc():

import traceback

def reader(args):

try:

# Insert stuff to be multiprocessed here

return args[0]['that']

except:

print "FATAL: reader({0}) exited while multiprocessing".format(args)

traceback.print_exc()

現在,當你發現一個崩潰,你會看到:

FATAL: reader([{'crash', 'this'}]) exited while multiprocessing

Traceback (most recent call last):

File "foo.py", line 19, in __init__

self.run(task_q, result_q)

File "foo.py", line 46, in run

raise ValueError

ValueError

源代碼:

"""

multi_pipe.py

"""

from multiprocessing import Process, Pipe

import time

def reader(pipe):

output_p, input_p = pipe

input_p.close() # We are only reading

while True:

try:

msg = output_p.recv() # Read from the output pipe and do nothing

except EOFError:

break

def writer(count, input_p):

for ii in xrange(0, count):

input_p.send(ii) # Write 'count' numbers into the input pipe

if __name__=='__main__':

for count in [10**4, 10**5, 10**6]:

output_p, input_p = Pipe()

reader_p = Process(target=reader, args=((output_p, input_p),))

reader_p.start() # Launch the reader process

output_p.close() # We no longer need this part of the Pipe()

_start = time.time()

writer(count, input_p) # Send a lot of stuff to reader()

input_p.close() # Ask the reader to stop when it reads EOF

reader_p.join()

print "Sending %s numbers to Pipe() took %s seconds" % (count,

(time.time() - _start))

"""

multi_queue.py

"""

from multiprocessing import Process, Queue

import time

def reader(queue):

while True:

msg = queue.get() # Read from the queue and do nothing

if (msg == 'DONE'):

break

def writer(count, queue):

for ii in xrange(0, count):

queue.put(ii) # Write 'count' numbers into the queue

queue.put('DONE')

if __name__=='__main__':

for count in [10**4, 10**5, 10**6]:

queue = Queue() # reader() reads from queue

# writer() writes to queue

reader_p = Process(target=reader, args=((queue),))

reader_p.daemon = True

reader_p.start() # Launch the reader process

_start = time.time()

writer(count, queue) # Send a lot of stuff to reader()

reader_p.join() # Wait for the reader to finish

print "Sending %s numbers to Queue() took %s seconds" % (count,

(time.time() - _start))

"""

multi_joinablequeue.py

"""

from multiprocessing import Process, JoinableQueue

import time

def reader(queue):

while True:

msg = queue.get() # Read from the queue and do nothing

queue.task_done()

def writer(count, queue):

for ii in xrange(0, count):

queue.put(ii) # Write 'count' numbers into the queue

if __name__=='__main__':

for count in [10**4, 10**5, 10**6]:

queue = JoinableQueue() # reader() reads from queue

# writer() writes to queue

reader_p = Process(target=reader, args=((queue),))

reader_p.daemon = True

reader_p.start() # Launch the reader process

_start = time.time()

writer(count, queue) # Send a lot of stuff to reader()

queue.join() # Wait for the reader to finish

print "Sending %s numbers to JoinableQueue() took %s seconds" % (count,

(time.time() - _start))

總結

以上是生活随笔為你收集整理的python 管道队列_Python多处理 – 管道与队列的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 法国经典free性复古xxxx | 欧美在线视频免费播放 | 天堂网av手机版 | 黄色av高清| 国产一区视频观看 | 亚洲永久av | 日本一区二区久久 | 亚洲综合在线一区 | 日韩www| 国产一区二区三区中文字幕 | 奇米影视一区二区 | 亚色av | 午夜网站在线 | 我要看黄色大片 | 香蕉视频网页版 | 成人免费视频国产免费麻豆 | 激情久久免费视频 | 小视频国产 | 可以看的黄色网 | 国产黄a三级三级看三级 | 中国无码人妻丰满熟妇啪啪软件 | 影音先锋在线中文字幕 | 久久久夜 | 亚洲资源在线播放 | 欧美麻豆 | 久久久久亚洲AV | brazzers欧美极品少妇 | 国产一区二区视频在线观看免费 | 韩国性经典xxxxhd | 亚洲女同女同女同女同女同69 | 亚洲国产高清视频 | 日日爱夜夜爱 | www.污视频| 天堂一区二区三区 | 久久久久久国产 | 久久久精品麻豆 | 亚洲色诱 | 又黄又爽的视频在线观看 | 成人性生交视频免费观看 | 日韩精品中文字幕在线播放 | 国产精品一二三区视频 | 超碰超碰超碰超碰超碰 | 波多野在线视频 | 亚洲中文字幕无码一区 | 国产成人精品一区二区三区网站观看 | 精品人妻aV中文字幕乱码色欲 | 成人午夜又粗又硬又大 | 在线观看免费福利 | 日日草日日干 | av最新天堂 | 激情狠狠 | 国产欧美一区二区三区免费看 | 色羞羞| 丝袜美腿av在线 | 亚洲在线免费 | 国产麻豆精品在线观看 | 欧美12--15处交性娇小 | 爽爽影院在线免费观看 | 日韩午夜在线 | 91大神在线免费观看 | 欧洲毛片 | 依依成人综合 | 久久久国产精品黄毛片 | 天天干夜夜撸 | 性色欲网站人妻丰满中文久久不卡 | 精品国产视频一区二区 | 一区二区三区四区在线 | 黄页网站视频在线观看 | 好色先生视频污 | 国产精品高潮呻吟av | 神马久久久久久久久久久 | 99国产免费| 亚洲一区二区激情 | 男女叼嘿视频 | 国产,日韩,欧美 | 真实乱视频国产免费观看 | 国产区视频在线 | 国内外成人免费视频 | 少妇av在线| 亚洲成人 av| 午夜h视频 | 亚洲在线视频网站 | 国产不卡视频在线观看 | 国产人成一区二区三区影院 | 国产精品成人久久久久 | 一区二区三区久久久 | 久久中文字幕人妻熟av女蜜柚m | 中文字幕一区二区三区免费视频 | 成人综合在线视频 | 免费黄色入口 | 国产一区啪啪 | 热热久| 五月婷婷视频 | av手机免费在线观看 | 人妻少妇精品一区二区三区 | 神马久久久久久 | 国产成人精品影视 | 国产精品日韩无码 | 欧美一区一区 |