如何在 Python uwsgi 应用程序中处理正常关机 [英] How to handle graceful shutdown in Python uwsgi application

查看:39
本文介绍了如何在 Python uwsgi 应用程序中处理正常关机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 Python uwsgi 应用程序,它遵循基本模式:

I have a simple Python uwsgi app, that follows the basic pattern:

def application(env, start_response):
    ... do something ...
    ... create some threads ...
    ... handover the work to the threads ...
    start_response('200 OK', [('Content-Type','text/html')])
    return result

我的系统管理员抱怨我的应用程序没有处理关闭,每次他想重新启动 uwsgi 服务时,他都必须等待 uwsgi 的超时来终止应用程序进程.显然,这可能需要长达 30 秒的时间,服务不可用的时间.

My sysadmin is complaining that my app is not handling shutdown and he has to wait for uwsgi's timeout to kill the app processes each time he wants to restart the uwsgi service. Which, apparently, can take up to 30 seconds, time in which the service is unavailable.

是否有特定的信号或调用 uwsgi 在要关闭应用程序时发送该应用程序?我该如何处理?

Is there a specific signal or call that uwsgi sends the app when it wants to close it? How do I handle that?

推荐答案

def goodbye():
    print "Goodbye from worker %d" % uwsgi.worker_id()

uwsgi.atexit = goodbye

或者这个标准的python模块

这篇关于如何在 Python uwsgi 应用程序中处理正常关机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆