国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python 多進程通信模塊的簡單實現

2020-02-23 05:09:18
字體:
來源:轉載
供稿:網友

多進程通信方法好多,不一而數。剛才試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)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 岱山县| 永嘉县| 江陵县| 平度市| 喀什市| 高唐县| 榆树市| 尖扎县| 乐安县| 乌兰县| 大冶市| 城口县| 买车| 繁峙县| 庄浪县| 格尔木市| 裕民县| 望江县| 梨树县| 逊克县| 神池县| 班戈县| 双城市| 长白| 白玉县| 东乡县| 英山县| 阜城县| 长沙县| 和政县| 通河县| 长岭县| 丰原市| 轮台县| 延川县| 隆安县| 绥棱县| 莱芜市| 中阳县| 仙桃市| 高州市|