用threading 解决 gunicorn worker timeout
产生worker timeout 的背景
while 1:
.....
time.sleep(1)
gunicorn运行起来,只等待了30s,就卡住了,没报任何异常或err,查了gunicorn 官方文档,原来是线程默认等待30s 就kill 掉,再restart
http://docs.gunicorn.org/en/stable/settings.html
timeout
-t INT, --timeout INT30
Workers silent for more than this many seconds are killed and restarted.
Generally set to thirty seconds. Only set this noticeably higher if you’re sure of the repercussions for sync workers. For the non sync workers it just means that the worker process is still communicating and is not tied to the length of time required to handle a single request.
根本原因找到了,在gunicorn启动加了--timeout 120 ,还是超过30s 就worker timeout.搜了一圈stack没发现好的解决方法。
解决这个问题,目前最好的方法,就是在程序改代码,原先是主线程调用,用threading包装一下
如:
import threading
t = threading.Thread(name = '', target = func ,kwargs{})
t.daemon = True
t.start()
t = threading.Thread(name='result_package', target=result_package, args=(pack_name, task, issue))
t.daemon = True
t.start()
这样就在主线程下,把方法包装起来。
顺便用
Event().wait(15) 替代 time.sleep(16)
这样写法的好处是不占用cpu,释放!
刚开始,分析原因花了不少时间,几行代码就把worker timeout解决了。之前试了map.thread不行。
准备用队列(celery+redis)替代原来的逻辑,只是工作量有点大,太重了。
用threading 解决 gunicorn worker timeout的更多相关文章
- --解决Lock wait timeout exceeded; try restarting transaction
--解决Lock wait timeout exceeded; try restarting transaction select * from information_schema.innodb_t ...
- 更改pip安装源的镜像解决安装总是timeout的情况
由于国外的pip源总是由于各种原因不能被访问或者网速过慢,而造成的timeout错误 解决方法是修改pip的配置文件(如果没有配置文件在相应的地方新建,配置文件的路径和名字参考这里),设置安装包时候访 ...
- 解决 504 Gateway Time-out和502 Bad Gateway(nginx)
504 Gateway Time-out 问题所在: 所请求的网关没有请求到,简单来说就是没有请求到可以执行的PHP-CGI. 一般看来, 这种情况可能是由于nginx默认的fastcgi进程响应的缓 ...
- 解决InetAddress.isReachable(timeout)在windows xp始终返回false的bug
笔者最近在做产品,其中一个环节用到ping测试主机是否在线. 开发环境:Windows 7 64bit+JDK1.8 x64 以下是检测主机是否在线,开发环境中测试通过 public static b ...
- 更改pip安装源的镜像解决安装总是timeout的情况(pip 豆瓣镜像源)
由于国外的pip源总是由于各种原因不能被访问或者网速过慢,而造成的timeout错误 解决方法是修改pip的配置文件(如果没有配置文件在相应的地方新建,配置文件的路径和名字参考这里),设置安装包时候访 ...
- 如何解决“504 Gateway Time-out”错误
做网站的同学经常会发现一些nginx服务器访问时候提示504 Gateway Time-out错误,一般情况下是由nginx默认的fastcgi进程响应慢引起的,但也有其他情况,这里我总结了一些解决办 ...
- 解决504 Gateway Time-out(nginx)
504 Gateway Time-out问题常见于使用nginx作为web server的服务器的网站 我遇到这个问题是在需要插入一万多条数据时候遇到的 一般看来, 这种情况可能是由于nginx默认的 ...
- 解决jenkins git timeout的问题
进入项目配置(project configure) "源码管理"选项卡中,找到Additional Behaviours点击旁边的 add image.png 点击advanc ...
- 解决zabbix“ZBX_NOTSUPPORTED: Timeout while executing a shell script”报错
如题所示,在zabbix_server使用zabbix_get获取自定义“UserParameter”对应的脚本的数据时,出现了如题所示的报错信息 [root@nmp01 scripts]# /usr ...
随机推荐
- JavaScript Sort
function ArrayList() { var array = []; this.swap = function(index1, index2) { var aux = array[index1 ...
- HttpUrlConnection工具类
package com.ligotop.core.utils; import com.ligotop.core.exceptions.BusinessException; import java.io ...
- Eclipse Kepler安装WST Server Adapter后创建Server无Tomcat解决方法
在Eclipse Kepler下安装完WST Server Adapter后,创建Server时发现没有Tomcat服务器的选项,这个问题解决起来很简单, 只需要安装一下JST Server Adap ...
- RMQ(鸽巢原理或字符串操作)
http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) ...
- [fw]Understanding a Kernel Oops!
An “Oops” is what the kernel throws at us when it finds something faulty, or an exception, in the ke ...
- 消息中间件-技术专区-RocketMQ架构原理
RocketMQ是阿里开源的分布式消息中间件,跟其它中间件相比,RocketMQ的特点是纯JAVA实现:集群和HA实现相对简单:在发生宕机和其它故障时消息丢失率更低. 一.RocketMQ专业术语 P ...
- Linux学习笔记5(2)-CentOS7中Tomcat8修改jvm内存配置
1.进入tomcat的bin目录,比如我的在 /usr/local/apache-tomcat-8.5.16/bin 2.创建新的文件setenv.sh vi setenv.sh 并在此文件中添加以下 ...
- zabbix入门之配置邮件告警
zabbix入门之配置邮件告警 邮件环境搭建 使用本地邮箱账号发送邮件 zabbix-server 端安装 mailx .sendmail或者psotfix 服务,系统默认安装好了postfix #安 ...
- PHP: 双层 for循环的执行过程
先看代码 <?php for ($i = 0; $i<3; $i++) { for ($x = 0; $x<3; $x++) { // code... } } ?> 看下它的执 ...
- jenkins持续集成(一): 在Linux下的安装与配置
撸了今年阿里.网易和美团的面试,我有一个重要发现.......>>> 前提: 安装了JDK,并配置好环境变量:JAVA_HOME 安装了Maven,并配置好环境变量:MAVEN_HO ...