python 多進程通信模塊的簡單實現(xiàn)
多進程通信方法好多,不一而數(shù)。剛才試python封裝好嘅多進程通信模塊 multiprocessing.connection。
簡單測試咗一下,效率還可以,應該系對socket封裝,效率可以達到4krps,可以滿足好多方面嘅需求啦。
附代碼如下:
client
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" download - slave
"""
__author__ = 'Zagfai'
__license__ = 'MIT@2014-02'
import webtul
from multiprocessing.connection import Client
a = 0
try:
while True:
a += 1
address = ('10.33.41.112', 6666)
conn = Client(address, authkey='hellokey')
#print conn.recv()
d = conn.recv()
conn.close()
except:
pass
print a
server
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" downloader - master server
"""
__author__ = 'Zagfai'
__license__ = 'MIT@2014-02'
import webtul
from multiprocessing.connection import Listener
from threading import Thread
def listener():
address = ('10.33.41.112', 6666)
listener = Listener(address, backlog=100, authkey='hellokey')
while True:
conn = listener.accept()
#print 'connection accepted from', listener.last_accepted
try:
conn.send({'1':2, '2':'abc'})
except Exception, e:
print e
finally:
conn.close()
listener.close()
listener_th = Thread(target=listener)
listener_th.daemon = True
listener_th.start()
listener_th.join(timeout=20)
相關文章
Centos7下源碼安裝Python3 及shell 腳本自動安裝Python3的教程
這篇文章主要介紹了Centos7下源碼安裝Python3 shell 腳本自動安裝Python3的相關知識,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03
python pytorch模型轉onnx模型的全過程(多輸入+動態(tài)維度)
這篇文章主要介紹了python pytorch模型轉onnx模型的全過程(多輸入+動態(tài)維度),本文給大家記錄記錄了pt文件轉onnx全過程,簡單的修改即可應用,結合實例代碼給大家介紹的非常詳細,感興趣的朋友一起看看吧2024-03-03
Python 實現(xiàn)數(shù)據(jù)結構-堆棧和隊列的操作方法
隊、棧和鏈表一樣,在數(shù)據(jù)結構中非常基礎一種數(shù)據(jù)結構,同樣他們也有各種各樣、五花八門的變形和實現(xiàn)方式。這篇文章主要介紹了Python 實現(xiàn)數(shù)據(jù)結構-堆棧和隊列的操作方法,需要的朋友可以參考下2019-07-07
opencv python 圖片讀取與顯示圖片窗口未響應問題的解決
這篇文章主要介紹了opencv python 圖片讀取與顯示圖片窗口未響應問題的解決,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04
Python+selenium實現(xiàn)趣頭條的視頻自動上傳與發(fā)布
本文主要介紹了通過Python+selenium實現(xiàn)趣頭條的短視頻自動上傳與發(fā)布功能,同時支持抖音、快手、b站、小紅書等平臺的視頻自動化同步發(fā)布。需要的朋友可以參考一下2021-12-12
Python+ChatGPT實戰(zhàn)之進行游戲運營數(shù)據(jù)分析
最近ChatGPT蠻火的,今天試著讓ta用Python語言寫了一篇數(shù)據(jù)分析實戰(zhàn)案例。文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2023-02-02

