阿里云:
- celery版本注意事项 pip uninstall celery
pip install celery==3.1.24
pip install redis==2.10.6
- celery 不能以root用户启动 C_FORCE_ROOT
报错信息:
Running a worker with superuser privileges when the
worker accepts messages serialized with pickle is a very bad idea!
If you really want to continue then you have to set the C_FORCE_ROOT
environment variable (but please think about this before you do).
解决方法:在主文件里加
from celery import Celery, platforms
platforms.C_FORCE_ROOT = True
- redis服务要开启
参考: 链接
sudo apt update
sudo apt install redis-server
#启动Redis
redis-server
- 开启celery 服务
celery -A app:celery worker -l info
#app是文件名,app.py celery是启动app里的celery
- 系统变量的设置问题
描述:类似邮箱密码不能写入代码中,需要以系统变量的形式写入,但是直接用export口令写入只是临时变量,下次登录之前写入的变量就没有了。
raise SMTPServerDisconnected('please run connect() first')
smtplib.SMTPServerDisconnected: please run connect() first
116.228.90.34 - - [28/Oct/2020 16:56:36] "POST /zw/v1.0/email/send HTTP/1.1" 500 -
解决方法:
vim /etc/profile
进入编辑模式,
export variable=value
:wq! ###保存
具体参考:链接
邮件接口没有通
解决方法:需要特殊备案申请,阿里云或者腾讯云在官网个人用户界面申请开通邮件服务使用域名
在app.run() 中加ssl_context(域名的pem和key,注:需要添加pem和key的路径)flask编码导致的报错
问题:使用send_mail发送邮件报编码错误
UnicodeEncodeError: 'ascii' codec can't encode characters in
解决方法:把所有文本的ascii的编码全部统一为gbk
- linux后台运行代码
nohup python xxxx.py &
nohup celery -A app:celery worker -l info > zw_celery_out.log 2>&1 &
nohup python xxxx.py > xxx.log 2>&1 & #将程序调用记录输出在当前路径下的xxx.log
nohup python xxxx.py 2>&1 & #默认输出在当前路径下的nohup.out
- 查看/关闭当前客户端开启的后台服务
查看:jobs
关闭:kill %num #num代表目前的服务编号
暂停服务:fg %num
将后台暂停的服务继续执行: bg %num
- 查看后台程序运行日志
tail -f xxxx.log #注意路径
ctrl+c退出
- 关闭进程
ps aux
kill -9 [进程pid]
- 激活虚拟环境/关闭虚拟环境
source [虚拟环境的路径/bin/activate]
source env/bin/activate
deactivate
- 关闭celery进程
pkill -f "celery worker"
ps aux|grep celery
kill -9 [进程号]
- linux端口开启
sudo ufw status
- 切换root权限
sudo -i
- celey不能用root用户启动问题 C_FORCE_ROOT environment
Running a worker with superuser privileges when the
worker accepts messages serialized with pickle is a very bad idea!
If you really want to continue then you have to set the C_FORCE_ROOT
environment variable (but please think about this before you do).
解决方案:
from celery import Celery, platforms
platforms.C_FORCE_ROOT = True #加上这一行
- 清空文件夹
rm -rf [文件夹名]