我在uwsgi/emeror/nginx服务器上编码有很大问题.我的应用程序开发为批处理excel文件处理.
我使用最新版本的烧瓶和烧瓶扩展,并使用flask-excel.
我的应用程序在Digital Ocean/Ubuntu服务器上运行,我的配置文件是:
/etc/init/uwsgi.conf
description "uWSGI"
start on runlevel [2345]
stop on runlevel [06]
respawn
env UWSGI=/home/lukas/www/abissk/venv/bin/uwsgi
env LOGTO=/home/lukas/logs/abissk/emperor.log
exec $UWSGI --master --emperor /etc/uwsgi/vassals --die-on-term --uid www-data --gid www-data --logto $LOGTO
Run Code Online (Sandbox Code Playgroud)
/etc/uwsgi/vassals/abissk_uwsgi.ini
[uwsgi]
plugins = python
#pcre = True
#application's base folder
base = /home/lukas/www/abissk/
#enable-threads = true
#python module to import
app = wsgi
module = %(app)
home = %(base)venv
pythonpath = %(base)
#socket file's location
socket = /home/lukas/www/abissk/%n.sock
#permissions for the socket file
chmod-socket = 644
#the …Run Code Online (Sandbox Code Playgroud) 我的烧瓶项目基于Flask-Cookiecutter,我需要异步发送电子邮件。
发送电子邮件的功能由Miguel的教程配置,并且可以同步发送,但我不知道如何修改它以异步发送。
我的app.py
def create_app(config_object=ProdConfig):
app = Flask(__name__)
app.config.from_object(config_object)
register_extensions(app)
register_blueprints(app)
register_errorhandlers(app)
return app
def register_extensions(app):
assets.init_app(app)
bcrypt.init_app(app)
cache.init_app(app)
db.init_app(app)
login_manager.init_app(app)
debug_toolbar.init_app(app)
migrate.init_app(app, db)
mail.init_app(app)
return None
Run Code Online (Sandbox Code Playgroud)
我的view.py
from flask import current_app
@async
def send_async_email(current_app, msg):
with current_app.app_context():
print('##### spustam async')
mail.send(msg)
# Function for sending emails
def send_email(to, subject, template, **kwargs):
msg = Message(subject, recipients=[to])
msg.html = render_template('emails/' + template, **kwargs)
send_async_email(current_app, msg)
Run Code Online (Sandbox Code Playgroud)
在view.py中路由
@blueprint.route('/mailer', methods=['GET', 'POST'])
def mailer():
user = current_user.full_name
send_email(('name@gmail.com'),
'New mail', …Run Code Online (Sandbox Code Playgroud)