折腾:
期间,需要去研究,Flask中,如何去添加后台的进程,用于时间到期后,发送通知。
所以先去:
最后决定用:
Flask-RQ2
注:RQ==Redis Queue
基本用法,看官网貌似即可:
jezdez/Flask-RQ2: A Flask extension for RQ.
Flask-RQ2 — Flask-RQ2 16.0.2 documentation
但是还是要去搞清楚:
如何安装redis,配置redis
搜:
Flask-RQ 安装redis
使用 Python RQ 的 Python 执行后台任务 – 技术翻译 – 开源中国社区
基于redis又比celery更加简单的异步任务队列RQ | 峰云就她了
-》好像是redis用yum install redis即可。
python redis
python redis Flask-RQ
python redis Flask
Flask-Redis 0.3.0 : Python Package Index
underyx/flask-redis: A Flask extension for using Redis
pip安装flask-redis后,如何启动redis-server服务? 短知乎
“pip install redis是个python的redis库,并不是redis本身。redis安装看这个 Download – Redis”
flask+pypy+setuptools+redis+MySQLdb安装 – longxibendi的专栏 – 博客频道 – CSDN.NET
Flask+Nginx+Gunicorn+Redis+Mysql搭建一个小站 | Alex’s Blog
编写配置文件gunicorn.conf workers = 4 bind = ‘192.168.60.146:8888’ proc_name = ‘app’ pidfile = ‘/tmp/app.pid’ 执行: gunicorn –config gunicorn.conf app:app |
使用 flask-cache 时为什么不会使用全局 redis – V2EX
好像是:
需要先安装redis服务:
然后再安装flask-redis
再去安装flask-rq2
去安装
Flask 安装redis
[已解决]为Flask的后台任务而在CentOS中安装Redis
然后再去安装flask-redis
(SIPEvents) ➜ SIPEvents pip install flask-redis Collecting flask-redis Downloading Flask_Redis-0.3.0-py2.py3-none-any.whl Requirement already satisfied (use –upgrade to upgrade): Flask>=0.8 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from flask-redis) Collecting redis>=2.7.6 (from flask-redis) Downloading redis-2.10.5-py2.py3-none-any.whl (60kB) 100% |████████████████████████████████| 61kB 22kB/s Requirement already satisfied (use –upgrade to upgrade): itsdangerous>=0.21 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Flask>=0.8->flask-redis) Requirement already satisfied (use –upgrade to upgrade): Jinja2>=2.4 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Flask>=0.8->flask-redis) Requirement already satisfied (use –upgrade to upgrade): Werkzeug>=0.7 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Flask>=0.8->flask-redis) Requirement already satisfied (use –upgrade to upgrade): click>=2.0 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Flask>=0.8->flask-redis) Requirement already satisfied (use –upgrade to upgrade): MarkupSafe in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Jinja2>=2.4->Flask>=0.8->flask-redis) Installing collected packages: redis, flask-redis Successfully installed flask-redis-0.3.0 redis-2.10.5 |
再去安装flask-rq2
(SIPEvents) ➜ SIPEvents pip install flask-rq2 Collecting flask-rq2 Downloading Flask_RQ2-16.0.2-py2.py3-none-any.whl Collecting rq-scheduler>=0.6.1 (from flask-rq2) Downloading rq_scheduler-0.7.0-py2.py3-none-any.whl Requirement already satisfied (use –upgrade to upgrade): Flask>=0.10 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from flask-rq2) Collecting rq>=0.6.0 (from flask-rq2) Downloading rq-0.6.0-py2.py3-none-any.whl (48kB) 100% |████████████████████████████████| 51kB 79kB/s Collecting croniter>=0.3.9 (from rq-scheduler>=0.6.1->flask-rq2) Downloading croniter-0.3.12.tar.gz Requirement already satisfied (use –upgrade to upgrade): itsdangerous>=0.21 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Flask>=0.10->flask-rq2) Requirement already satisfied (use –upgrade to upgrade): Jinja2>=2.4 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Flask>=0.10->flask-rq2) Requirement already satisfied (use –upgrade to upgrade): Werkzeug>=0.7 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Flask>=0.10->flask-rq2) Requirement already satisfied (use –upgrade to upgrade): click>=2.0 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Flask>=0.10->flask-rq2) Requirement already satisfied (use –upgrade to upgrade): redis>=2.7.0 in /root/Envs/SIPEvents/lib/python2.7/site-packages (from rq>=0.6.0->flask-rq2) Collecting python-dateutil (from croniter>=0.3.9->rq-scheduler>=0.6.1->flask-rq2) Downloading python_dateutil-2.5.3-py2.py3-none-any.whl (201kB) 100% |████████████████████████████████| 204kB 38kB/s Requirement already satisfied (use –upgrade to upgrade): setuptools in /root/Envs/SIPEvents/lib/python2.7/site-packages (from croniter>=0.3.9->rq-scheduler>=0.6.1->flask-rq2) Requirement already satisfied (use –upgrade to upgrade): MarkupSafe in /root/Envs/SIPEvents/lib/python2.7/site-packages (from Jinja2>=2.4->Flask>=0.10->flask-rq2) Requirement already satisfied (use –upgrade to upgrade): six>=1.5 in /root/Envs/SIPEvents/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from python-dateutil->croniter>=0.3.9->rq-scheduler>=0.6.1->flask-rq2) Building wheels for collected packages: croniter Running setup.py bdist_wheel for croniter … done Stored in directory: /root/.cache/pip/wheels/c2/c0/db/3991f61b3a5e5c019d3f81ca556d095b1618bf8166368caf1d Successfully built croniter Installing collected packages: python-dateutil, croniter, rq, rq-scheduler, flask-rq2 Successfully installed croniter-0.3.12 flask-rq2-16.0.2 python-dateutil-2.5.3 rq-0.6.0 rq-scheduler-0.7.0 |
然后继续参考官网:
jezdez/Flask-RQ2: A Flask extension for RQ.
API — Flask-RQ2 16.0.2 documentation
结果出错:
[已解决]用Flask-RQ2运行后台任务失败:ConnectionError Error 97 connecting to localhost 6379
然后:
然后接着就是具体如何使用Flask-RQ2,rq worker和rqscheduler的事情了:
[总结]
此处,Flask中添加后台任务,没有去用最著名的Celery,因为太重,不够轻量级。
而选择了比较简单,性能不差的RQ==Redis Queue
“rq是python的一个用redis做的队列,简单实用。”
而redis和RQ直接在Python的Flask中用起来,也还是有点点麻烦的。
所以有人又去封装了Flask中的redis和RQ,并且还有很多个封装。
最后选择了:
Flask-Redis
和
Flask-RQ2
具体的步骤是:
在虚拟环境中
1.用pip安装flask-redis和flask-rq2:
pip install flask-redis pip install flask-rq2 |
会自动安装所依赖的库:
installed flask-redis-0.3.0 redis-2.10.5
installed croniter-0.3.12 flask-rq2-16.0.2 python-dateutil-2.5.3 rq-0.6.0 rq-scheduler-0.7.0
2.安装redis
而对于:
Flask-Redis只是个粘合剂,只是个接口的封装,并没有安装真正的Redis,所以还要再去安装redis:
步骤如下:
wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make yum install -y tcl make test make install mkdir /etc/redis cp redis.conf /etc/redis redis-server /etc/redis/redis.conf |
详见过程见:
[已解决]为Flask的后台任务而在CentOS中安装Redis
转载请注明:在路上 » [已解决]Flask中添加后台进程用于提醒到期时发送通知