日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

python的multiprocessing多進(jìn)程通信的pipe和queue介紹_PHP教程

編輯Tag賺U幣
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

推薦:php列出mysql表所有行與列的方法
這篇文章主要介紹了php列出mysql表所有行和列的方法,涉及php操作mysql數(shù)據(jù)庫(kù)的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下 本文實(shí)例講述了php列出mysql表所有行和列的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下: 代碼如下:html head titleSelecting Data/tit

python的multiprocessing提供了IPC(Pipe和Queue),使Python多進(jìn)程并發(fā),效率上更高。本文我們就來(lái)詳細(xì)介紹一下pipe和queue。    

這兩天溫故了python的multiprocessing多進(jìn)程模塊,看到的pipe和queue這兩種ipc方式,啥事ipc? ipc就是進(jìn)程間的通信模式,常用的一半是socke,rpc,pipe和消息隊(duì)列等。


今個(gè)就再把pipe和queue搞搞。

python的multiprocessing多進(jìn)程通信的pipe和queue介紹   模板無(wú)憂(yōu)


不只是multiprocessing的pipe,包括其他的pipe實(shí)現(xiàn),都只是兩個(gè)進(jìn)程之間的游玩,我給你,你來(lái)接收 或者是你來(lái),我接收。 當(dāng)然也可以做成雙工的狀態(tài)。

queue的話(huà),可以有更多的進(jìn)程參與進(jìn)來(lái)。用法和一些別的queue差不多。


看下官網(wǎng)的文檔:

multiprocessing.Pipe([duplex])

Returns a pair (conn1, conn2) of Connection objects representing the ends of a pipe.

#兩個(gè)pipe對(duì)象。用這兩個(gè)對(duì)象,來(lái)互相的交流。


If duplex is True (the default) then the pipe is bidirectional. If duplex is False then the pipe is unidirectional: conn1 can only be used for receiving messages and conn2 can only be used for sending messages.


class multiprocessing.Queue([maxsize])

Returns a process shared queue implemented using a pipe and a few locks/semaphores. When a process first puts an item on the queue a feeder thread is started which transfers objects from a buffer into the pipe.

#隊(duì)列的最大數(shù)


The usual Queue.Empty and Queue.Full exceptions from the standard library’s Queue module are raised to signal timeouts.


Queue implements all the methods of Queue.Queue except for task_done() and join().


qsize()

Return the approximate size of the queue. Because of multithreading/multiprocessing semantics, this number is not reliable.

#隊(duì)列的大小


Note that this may raise NotImplementedError on Unix platforms like Mac OS X where sem_getvalue() is not implemented.


empty()

Return True if the queue is empty, False otherwise. Because of multithreading/multiprocessing semantics, this is not reliable.

#是否孔了。 如果是空的,他回返回一個(gè)True 的狀態(tài)。


full()

Return True if the queue is full, False otherwise. Because of multithreading/multiprocessing semantics, this is not reliable.

#隊(duì)列的狀態(tài)是否滿(mǎn)了。


put(obj[, block[, timeout]])

Put obj into the queue. If the optional argument block is True (the default) and timeout is None (the default), block if necessary until a free slot is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Queue.Full exception if no free slot was available within that time. Otherwise (block is False), put an item on the queue if a free slot is immediately available, else raise the Queue.Full exception (timeout is ignored in that case).

#塞入隊(duì)列,可以加超時(shí)的時(shí)間。

put_nowait(obj)

Equivalent to put(obj, False).

#這里是不堵塞的


get([block[, timeout]])

Remove and return an item from the queue. If optional args block is True (the default) and timeout is None (the default), block if necessary until an item is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Queue.Empty exception if no item was available within that time. Otherwise (block is False), return an item if one is immediately available, else raise the Queue.Empty exception (timeout is ignored in that case).

#獲取狀態(tài)


get_nowait()

Equivalent to get(False).

#不堵塞的get隊(duì)列里面的數(shù)據(jù)


Queue has a few additional methods not found in Queue.Queue. These methods are usually unnecessary for most code:


close()

Indicate that no more data will be put on this queue by the current process. The background thread will quit once it has flushed all buffered data to the pipe. This is called automatically when the queue is garbage collected.

#關(guān)閉,省當(dāng)前進(jìn)程的資源。



我配置了multiprocessing隊(duì)里長(zhǎng)度是3個(gè),然后當(dāng)我放入的是第四個(gè)的時(shí)候, 會(huì)發(fā)現(xiàn)一只的堵塞,他是在等待,有人把數(shù)據(jù)get掉一個(gè),那個(gè)時(shí)候 他才能繼續(xù)的塞入 。如果用put_nowait()的話(huà),隊(duì)列超出會(huì)立馬會(huì)一個(gè)error的。


/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.pyc in put_nowait(self, obj)


/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.pyc in put(self, obj, block, timeout)

wKioL1QMjmuR30vjAAOEnmz0ElE220.jpg


下面是一段測(cè)試的代碼,同學(xué)們可以跑跑demo,感受下。

wKiom1QMigmjsp8LAANICa7A4dI435.jpg

好了,簡(jiǎn)單講講了 pipe和queue的用法。 其實(shí)我今個(gè)本來(lái)想扯扯python pipe的,結(jié)果google一搜,看到了multiprocessing的pipe。寫(xiě)完了pipe后,感覺(jué)文章的內(nèi)容太少了,所以我才額外的增加了queue的。。。

分享:PHP使用DirectoryIterator顯示下拉文件列表的方法
這篇文章主要介紹了PHP使用DirectoryIterator顯示下拉文件列表的方法,涉及php使用DirectoryIterator操作文件的技巧,需要的朋友可以參考下 本文實(shí)例講述了PHP使用DirectoryIterator顯示下拉文件列表的方法。分享給大家供大家參考。具體分析如下: PHP中使用DirectoryIte

來(lái)源:模板無(wú)憂(yōu)//所屬分類(lèi):PHP教程/更新時(shí)間:2015-03-16
相關(guān)PHP教程