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

Linux下uWSGI中spawn方法导致Python multiprocessing Manager失效问题

问题:Ubuntu 22.04.2 LTS下uWSGI+torch.multiprocessing spawn启动异常

在Ubuntu 22.04.2 LTS系统部署uWSGI应用时,使用torch.multiprocessing的spawn启动方法初始化Manager会触发异常,报错提示无法加载multiprocessing.resource_tracker配置,且uwsgi-core不识别--multiprocessing-fork选项。切换为fork启动方法则可正常运行。

相关代码

from torch.multiprocessing import Manager                                                                                                                    
import torch.multiprocessing as mp          

if __name__ == 'uwsgi_file__home_kasha_uwsgi_test_test':
  ctx = mp.set_start_method('spawn')
  m = mp.Manager()
            
def application(env, start_response):
  start_response('200 OK', [('Content-Type','text/html')])
  return [b"Hello World"]

运行命令

uwsgi --ini ./test.ini

错误信息

unable to load configuration from from multiprocessing.resource_tracker import main;main(9)
/usr/bin/uwsgi-core: unrecognized option '--multiprocessing-fork'

uWSGI配置文件test.ini

[uwsgi]
master = true
processes = 1

socket = 127.0.0.1:9000
buffer-size=32768
#protocol = http-socket                                                                                                                                   
socket = /home/kasha/uwsgi_test/test.sock
chown-socket = kasha:kasha

vacuum = true

die-on-term = true
plugins = python3
#logto = /home/kasha/uwsgi_test/err.log                                                                                                                     

wsgi-file = /home/kasha/uwsgi_test/test.py
lazy = true
enable-threads = false

临时解决方案:将torch.multiprocessing的启动方法从spawn改为fork,即可避免该异常,应用正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 21:18:14