python 多进程通信模块的简单实现
时间:2021-06-13 08:21:32
多进程通信方法好多,不一而数。刚才试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)
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
node.js+express+mySQL+ejs+bootstrop实现网站登录注册功能
![](https://img.aspxhome.com/file/2023/9/55989_0s.gif)
ASP伪静态页简单教程
未能加载文件或程序集“XXX”或它的某一个依赖项。试图加载格式不正确的程序。
Django中使用Celery的教程详解
![](https://img.aspxhome.com/file/2023/7/91927_0s.png)
Ubuntu下安装卸载python3.8的过程
经典的退出浏览器弹窗代码
nlp计数法应用于PTB数据集示例详解
ASP使用MYSQL数据库全攻略
Python多叉树的构造及取出节点数据(treelib)的方法
Oracle回滚段的概念,用法和规划及问题的解决
对mysql表进行优化、分析、检查和修复的说明
Python读取HTML中的canvas并且以图片形式存入Word文档
![](https://img.aspxhome.com/file/2023/0/89430_0s.png)
CSS网页设计时关于字体大小的设计
DTS构建组件及其如何完成数据转换服务
用Python编写个解释器实现方法接受
![](https://img.aspxhome.com/file/2023/5/65505_0s.png)
Python爬虫使用脚本登录Github并查看信息
![](https://img.aspxhome.com/file/2023/9/83899_0s.png)
Python中的异常处理相关语句基础学习笔记
Django返回HTML文件的实现方法
![](https://img.aspxhome.com/file/2023/8/79458_0s.png)
浅谈pytorch中stack和cat的及to_tensor的坑
Python中的Numpy 面向数组编程常见操作
![](https://img.aspxhome.com/file/2023/9/71409_0s.png)