python - 多处理——从多个运行时接收所有消息?
问题描述
我一直在尝试制作一个允许多个其他程序连接并向单个端口发送消息的程序。问题是,在某些时候,似乎在多处理模块的深处,os.read
对两端的调用都会挂起。
演示receive.py
:
from multiprocessing.connection import Listener
while True:
with Listener(("localhost", 10000), authkey=b"test") as listener:
with listener.accept() as connection:
print(connection.recv())
Demo send.py
(发送1000次模仿多个程序,暴露问题):
from multiprocessing.connection import Client
for i in range(1000):
successfully_sent = False
while not successfully_sent:
try:
with Client(("localhost", 10000), authkey=b"test") as client:
client.send(i)
except (ConnectionRefusedError, ConnectionResetError):
continue
successfully_sent = True
任何有关如何强制进程继续而不丢失任何消息的提示将不胜感激。我考虑过在receive.py 中使用线程来强制超时,但我希望有一种更简洁的方法可以解决根本问题。另外,这是一个错误吗?
解决方案
推荐阅读
- android - 使用 MDC 在 android 中创建材质微调器下拉列表
- javascript - 使用 React.JS 将图像文件与其他数据一起发送到 Java 后端
- r - 以特定格式打印 R 字符串
- virtocommerce - 如何解决 Virto Commerce 主题丢失错误?
- javascript - 为什么 redux-loop 操作会跳过所有中间件?
- python - 如何通过数据框中的列循环函数并添加到新列
- z3 - z3不解量词表达式,表达式为sat
- html - 停止移动菜单后面的文本滚动
- java - 为什么控制器显示问题而不是西里尔字符?
- google-chrome-devtools - 当返回“no-store, no-cache, must-revalidate”时,Chrome 的开发者工具会显示响应内容吗?