uwsgi+python支持多线程

今天使用uwsgi+python+Thread模块实现接收到请求之后主进程立刻返回同时创建一个线程后台处理,而不是同步处理请求,避免导致请求时间过长http请求断开以及卡主操作页面的问题,修改完之后并没有生效,仍然是同步的,之后看到uwsgi的log里面有写默认不支持python多线程特性,需要使用enable-threads打开才行,之后在uwsgi启动选项中添加了–enable-threads参数,但是发现仍然不行,log中仍然有输出需要打开的信息。官方文档如下

--enable-threads

By default uWSGI does not enable threading support within the Python interpreter core. This means it is not possible to create background threads from Python code. As the Python agent relies on being able to create background threads, this option is required. This option will be automatically applied if uWSGI is configured for multiple threads using the –threads option.



uwsgi配置,既可以在启动参数里面指定,也可以在每个cgi的配置里面指定如下加粗字体添加上之后生效

[uwsgi]

socket = :9001

stats = :9093

wsgi-file = index.py

callable = app

chdir = /search/service/nginx/html/opWeb

master = true

processes = 4

pidfile = /var/run/uwsgi/opweb.pid

daemonize = /var/log/uwsgi/opweb.log

harakiri = 600

enable-threads = true

转载请注明来源链接 http://just4fun.im/2017/03/19/uwsgipython-e6-94-af-e6-8c-81-e5-a4-9a-e7-ba-bf-e7-a8-8b/ 尊重知识,谢谢:)