uwsgi+flask+apscheduler 定时任务不执行

uwsgi+flask+apscheduler 定时任务不执行

在本地项目中使用APScheduler运行定时任务ok,但是在服务器上用uwsgi部署的Django环境下,APScheduler定时任务并不会被启动。

原因:uwsgi 默认one thread one processor ,所以在没有请求的时候,导致部分进程被挂起

在uwsgi.ini文件中加入

enable-threads=true

preload=true

lazy-apps=true

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是基于 CentOS 操作系统的 Nginx + Uwsgi + Flask 部署服务的详细操作步骤: 1. 安装必要的软件包 ```bash yum install epel-release yum install nginx yum install python3 python3-pip pip3 install uwsgi flask ``` 2. 创建 Flask 应用程序 在服务器上创建 Flask 应用程序,例如: ```python from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run() ``` 3. 创建 uwsgi 配置文件 在服务器上创建一个 uwsgi 配置文件,例如: ```ini [uwsgi] module = wsgi:app master = true processes = 5 socket = /tmp/uwsgi.sock chmod-socket = 660 vacuum = true die-on-term = true ``` 其中,`module` 参数指定 Flask 应用程序所在的模块和变量名,`socket` 参数指定 uwsgi 与 Nginx 通信的 Unix 套接字文件位置。 4. 创建 Nginx 配置文件 在服务器上创建一个 Nginx 配置文件,例如: ```nginx server { listen 80; server_name your-domain.com; location / { include uwsgi_params; uwsgi_pass unix:/tmp/uwsgi.sock; } } ``` 其中,`listen` 参数指定监听的端口,`server_name` 参数指定服务器的域名或 IP 地址,`location` 参数指定请求 URL 的路径,`uwsgi_pass` 参数指定 uwsgi 与 Nginx 通信的 Unix 套接字文件位置。 5. 启动服务服务器上启动 uwsgi 和 Nginx 服务: ```bash uwsgi --ini uwsgi.ini & systemctl start nginx ``` 6. 测试服务 在浏览器中输入服务器的域名或 IP 地址,应该能够看到 Hello, World! 的输出。 以上就是在 CentOS 上使用 Nginx + Uwsgi + Flask 部署服务的详细操作步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值