记录一个奇怪的问题,暂时解决,但是没有找到根本原因,有空再回来解决 # gunicornconf.py import os home = '/home/ops' print('home:'+home) bind = '0.0.0.0:8000' #绑定ip和端口号 backlog = 512 #监听队列 chdir = home+'/server/bin' #gunicorn要切换到的目的工作目录 timeout = 30 #超时 worker_class = 'sync' #使用gevent模式,还可以使用sync 模式,默认的是sync模式 workers = 3 #+ multiprocessing.cpu_count() * 2 #进程数 threads = 2 #指定每个进程开启的线程数 loglevel = 'debug' #日志级别,这个日志级别指的是错误日志的级别,而访问日志的级别无法设置 access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"' #设置gunicorn访问日志格式,错误日志无法设置 """ 其每个选项的含义如下: h remote address l '-' u currently '-', may be user name in future releases t date of the request r status line (e.g. ``GET / HTTP/1.1``) s status b response length or '-' f referer a user agent T request time in seconds D request time in microseconds L request time in decimal seconds p process ID """ accesslog = home+"/server/log/gunicorn_access.log" #访问日志文件 errorlog = home+"/server/log/gunicorn_error.log" #
#flaskapi.py import sys import os curPath = os.path.abspath(os.path.dirname(__file__)) rootPath = os.path.split(curPath)[0] sys.path.append(rootPath) print('rootPath:'+rootPath) print('syspath:' +str(sys.path)) from flask import Flask import logging from chatbox.chatmodel import retrieval_milvus logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', level = logging.DEBUG) def create_app(): app = Flask(__name__) return app app = create_app() @app.route('/chatbots/<words>') def get_answer(words): try: print(words) try: answer_id= retrieval_milvus(words) except Exception as E: logging.error('exception:' + str(E)) return '留言转接中,请稍等。。。' return answer_id except Exception as E: logging.error('exception:' + str(E)) return 'Error' if __name__ == '__main__': app.run()
现象: gunicorn 进程不断重启,CRITICAL WORKER TIMEOUT
查看下面issue后尝试也没有找到办法,但是修改worker_class后暂时能跑了,本来是gevent模式,改成worker_class = 'sync'后能跑了,原因未知,有空回来看
worker_class = 'sync' #使用gevent模式,还可以使用sync 模式,默认的是sync模式
CRITICAL WORKER TIMEOUT when running Flask app · Issue #1801 · benoitc/gunicorn · GitHubhttps://hub.fastgit.org/benoitc/gunicorn/issues/1801