You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ForkingTCPServer时multiprocessing Queue随机丢元素问题

多进程HTTP服务器中Queue元素堆积、get()丢失元素的问题

我对多进程技术经验有限,最近开发小型HTTP/API服务器时碰到了问题:用户需要多次点击登录才能成功。

我尝试剥离http.server相关代码单独测试,却无法复现该问题,因此整理了一份最小复现代码。当前核心现象为:队列元素持续堆积,但调用queue.get()时会忽略部分元素,即使设置block=False也无改善。

运行输出示例:

Queue current size: 6
Fetched element: 2
Queue current size: 5
Fetched element: 4
Queue current size: 4
...

内容的提问来源于stack exchange,提问作者Cosh Marius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 18:34:51