产生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 INT
30
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)替代原来的逻辑,只是工作量有点大,太重了。
相关推荐
主要介绍了python使用threading获取线程函数返回值的实现方法,需要的朋友可以参考下
.Net 3.5 下使用的 System.Threading.Tasks。 安装完成后,添加引用时只需要在安装目录 C:\Program Files (x86)\Microsoft Reactive Extensions\Redist\DesktopV2 下找到 System.Threading.dll,添加即可
使用threading建立了一个多线程的基础程序 使用threading建立了一个多线程的基础程序 使用threading建立了一个多线程的基础程序 使用threading建立了一个多线程的基础程序 使用threading建立了一个多线程的基础...
1、为什么需要使用线程池 1.1 创建/销毁线程伴随着系统开销,过于频繁的创建/销毁线程,会很大程度上影响处理效率。 记创建线程消耗时间T1,执行任务消耗时间T2,销毁线程消耗时间T3,如果T1+T3>T2,那说明开启一个...
C#多线程操作控件threading的使用
system.Threading.Timer的使用
本文实例讲述了python多线程threading.Lock锁的用法实例,分享给大家供大家参考。...如果设定了timeout,则在超时后通过返回值可以判断是否得到了锁,从而可以进行一些其他的处理。 复制代码 代码如下:#!/usr/bin/env
Python的线程操作在旧版本中使用的是thread模块,在Python27和Python3中引入了threading模块,同时thread模块在Python3中改名为_thread模块,threading模块相较于thread模块,对于线程的操作更加的丰富,而且...
intel threading building blocks
国内牛人翻译的Threading in C#,是我见过的C#多线程技术讲的最深入、最全面的,鼎立推荐
本文结合threading模块源码及官方文档,对threading模块内容(类,方法,属性)进行了系统性的整理,通过阅读此文档便可对threading模块有一个系统性的认知
C++ Threading A Generic-Programming Approach kevlin@curbralan.com Kevlin Henney 2
Threading in C#中文
高清彩版 Efficient Android Threading
.Net 3.5支持Plinq的相关信息已被微软撤掉了, ...3.5可以使用1.0.3058.34407版本。通过小例子测试发现查询效率有极大的提高 using System.Threading.Tasks; using System.Threading; using System.Linq;
Efficient.Android.ThreadingEfficient.Android.Threading
C# Threading Handbook 英文版
1、多线程的理解 多进程和多线程都可以执行多个任务,线程是进程的一部分。线程的特点是线程之间可以...在Python中,同样可以实现多线程,有两个标准模块thread和threading,不过我们主要使用 更高级的threading模块。
Wrox - APress - C# Threading Handbook
学习threading.timer过程中作的测试软件,供初学者参考。