- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 Python 中添加一个 runloop 代码后,uWSGI 似乎需要更长的时间来杀死。
过去停止 uWSGI 非常快。最近我集成了一个后台线程来定期检查数据库并在需要时每 60 秒进行一次更改。
这似乎工作得很好,除了现在每次我试图杀死 uWSGI 时,都需要很长时间。
################################
## deploy.ini module .py file ##
################################
from controllers import runloop
from flask import Flask
from flask import request, redirect,Response
app = Flask(__name__)
runloop.startrunloop()
if __name__ == '__main__':
app.run() #app.run(debug=True)
################################
## runloop.py ##
################################
### initialize run loop ###
## code ref: http://stackoverflow.com/a/22900255/2298002
# "Your additional threads must be initiated from the same app that is called by the WSGI server.
# 'The example below creates a background thread that executes every 5 seconds and manipulates data
# structures that are also available to Flask routed functions."
#####################################################################
POOL_TIME = 60 #Seconds
# variables that are accessible from anywhere
commonDataStruct = {}
# lock to control access to variable
dataLock = threading.Lock()
# thread handler
yourThread = threading.Thread()
def startrunloop():
logfuncname = 'runloop.startrunloop'
logging.info(' >> %s >> ENTER ' % logfuncname)
def interrupt():
logging.info(' %s >>>> interrupt() ' % logfuncname)
global yourThread
yourThread.cancel()
def loopfunc():
logging.info(' %s >>> loopfunc() ' % logfuncname)
global commonDataStruct
global yourThread
with dataLock:
# Do your stuff with commonDataStruct Here
# function that performs at most 15 db queries (right now)
# this function will perform many times more db queries in production
auto_close_dws()
# Set the next thread to happen
yourThread = threading.Timer(POOL_TIME, loopfunc, ())
yourThread.start()
def initfunc():
# Do initialisation stuff here
logging.info(' %s >> initfunc() ' % logfuncname)
global yourThread
# Create your thread
yourThread = threading.Timer(POOL_TIME, loopfunc, ())
yourThread.start()
# Initiate
initfunc()
# When you kill Flask (SIGTERM), clear the trigger for the next thread
atexit.register(interrupt)
我启动服务器:
$ nginx
并停止:
$ nginx -s stop
我用以下方法启动 uWSGI:
$ uwsgi —enable-threads —ini deploy.ini
我停止 uWSGI 以进行 python 更改:
ctrl + c (if in the foreground)
否则我停止uWSGI:
$ killall -s INT uwsgi
然后在对 Python 代码进行更改后,我再次启动 uWSGI:
$ uwsgi —enable-threads —ini deploy.ini
以下是我尝试终止时 Nginx 输出的示例:
^CSIGINT/SIGQUIT received...killing workers...
Fri May 6 00:50:39 2016 - worker 1 (pid: 49552) is taking too much time to die...NO MERCY !!!
Fri May 6 00:50:39 2016 - worker 2 (pid: 49553) is taking too much time to die...NO MERCY !!!
非常感谢任何帮助或提示。如果我需要更清楚地了解任何事情或遗漏任何细节,请告诉我。
最佳答案
我知道这个问题有点老了,但我遇到了同样的问题,Google 把我带到了这里,所以我会回答任何在同一条船上来到这里的人。
问题似乎是由 --enable-threads
选项引起的,我们有几个运行 uwsgi 和 flask 的应用程序,只有这个选项有问题。
如果你想让 uwsgi 进程死得更快,你可以添加这个选项:
reload-mercy = *int*
worker-reload-mercy = *int*
它们会导致 uwsgi 在 int 秒后强制进程退出。
另一方面,如果您只需要重新加载 uwsgi,请尝试发送一个 SIGHUP 信号。这将导致 uwsgi 重新加载它的 child 。
POST NOTE: 看来我说得太早了,使用 SIGHUP
有时也会挂起。我正在使用怜悯选项来避免挂起时间过长。
此外,我在 uwsgi github 上找到了问题报告,如果有人想关注它:
关于python - uWSGI kill 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37846202/
uWSGI 主进程有什么用? 和/或我可以在哪里阅读更多相关信息? 我找到了零文档。 最佳答案 您可以找到有关大师的一些信息here和 here 一般来说,主文件负责优雅地重新加载您的应用程序服务器(
我有多个基于 Flask 的 web 应用程序在 docker 容器中运行(它们的进程需要与主机操作系统隔离)。为了运行这些应用程序,我在容器内使用了 uWSGI 服务器。传入的请求应该通过订阅服务器
我正在尝试使用 uwsgi 进行一些非常复杂的配置。从长远来看,我试图让自己的事情变得更容易,自然而然,这样做,我正在使事情变得尽可能困难。 无论如何,我正在寻找魔法变量的完整列表。我能在 Emper
我开始使用 uWSGI,我想知道它的工作人员是否是非阻塞/基于事件的(就像 nginx 一样)。 假设我已经像这样启动了 uWSGI: uwsgi --http :8000 --wsgi-file t
我们的应用程序是为 Python 2.7 编写的。它有一个配置为使用 Python 2.7 的 virtualenv。系统安装的 uWSGI 是用 Python 2.6 构建的。 It seems t
我在这个页面 http://uwsgi-docs.readthedocs.org/en/latest/StatsServer.html并使用 uwsgitop但我不知道如何解释输出。文档也没有透露太多
我看到这里发布了许多 uWSGI 配置,我在工作中遇到的现有应用程序的配置也有填充了 100 到 1000 值的 max-requests。 在一定数量的请求后回收进程的目的是什么?您是否试图避免内存
我正在使用 uWSGI 运行一个 webpy 网络服务器,有些请求花费的时间太长。设置 harakiri 模式后,我注意到请求被终止后会再次重试。 是否可以禁用此行为? 运行命令为: /usr/loc
uwsgi 中的“mule farm”是什么,它有什么用?有一些使用示例吗?我没有在文档或其他任何地方找到任何东西。 最佳答案 一群有名字的骡子 --farm chickens:1,2,3. --fa
在学习Python web开发时候,可能会遇到诸如uwsgi,wsgi等名词,下面通过梳理总结探究它们之间的关系。 CGI CGI,(Common Gateway Interface)通用网关接口,是
我已经使用 uWSGI 部署了一个 WSGI 应用程序,但是 I am not using NGINX .如何使用 uWSGI's internal routing将 http 请求重定向到 http
我正在使用命令在 uWsgi 服务器中测试应用程序, uwsgi --http :9090 --wsgi-file myapp.py --callable app --processes 4 --th
我们有一个工作的 uwsgi 服务器,带有一些 RPC 调用(注意:我们能够使用 uwsgi.rpc 与进程对话,因此它们端的设置很好)。我们发现我们有一些进程没有在 uwsgi 下运行,但我们想要与
我正在尝试为我的 Django 项目设置 uwsgi。它运行良好 ./manage.py runserver 0.0.0.0:9010 但是当我尝试 uwsgi --http :9010 --chd
我是 Linux 开发的新手。我对阅读的文档有点困惑。我的最终目标是托管一个简单的 python 支持的 Web 服务,该服务将检查传入的有效负载,并将其转发到其他服务器。这应该不到 30 行 pyt
我的 Django 应用程序倾向于使用 uwsgi+nginx,谁能分享启动我的 uwsgi 进程的最佳方法?有没有人有调整uwsgi的经验? 最佳答案 在 OSX 上启动 Unice 上的 Upst
从 ini 文件启动 uwsgi 时崩溃,堆栈跟踪如下: Traceback (most recent call last):
我用 Django 编写了一个服务器应用程序,并使用 Tastypie 为移动应用程序提供 API,并使用本地 MySQL 服务器为数据库提供服务。 在进程被杀死或结束之前,查询似乎被缓存了。如果我在
我正在开发一个基于 Python 的应用程序(HTTP -- REST 或 jsonrpc 接口(interface)),它将用于生产自动化测试环境。这将连接到运行所有测试脚本的 Java 客户端。即
我尝试在 nginx+uwsgi、os - debian (3.1.0-1-amd64 x86_64) 上为 django 建立网络服务器 nginx 1.1.8-1,uwsgi 0.9.8.3-1
我是一名优秀的程序员,十分优秀!