如何在服务器中启动Flask应用程序之前运行我的功能代码

时间:2019-07-11 14:29:59

标签: amazon-web-services nginx flask python-3.6 uwsgi

嗨,我有以下名为app.py的python文件

   def load_mode():
        print('ab') 

if __name__ == '__main__':
    load_model()
    app.run(debug=True)

当我在本地使用python app.py时,将执行load_mode函数。

当我使用具有以下设置的uwsgi和nginx在AWS服务器中的应用程序中部署时。

app.ini

[uwsgi]
# placeholders that you have to change
socket = 127.0.0.1:8000
plugins = python36
chidir = /home/ubuntu/app/src
wsgi-file = app.py
callable = app

master = true
processes = 4
# location of log files
logto =uwsgi.log
uwsgi_read_timeout = 2000
harakiri = 2000 

/etc/systemed/system/app.service中的服务设置

[Unit]
Description=uWSGI instance to serve app
After=network.target

[Service]
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/app
ExecStart=/usr/bin/uwsgi  --ini /home/ubuntu/app/src/app.ini
Restart=on-failure


[Install]
WantedBy=multi-user.target

为什么我使用nginx和uwsgi启动应用程序,所以不执行load_model的功能。实际上,我想执行负载模型功能。如何解决此问题,例如本地的pythonapp.py。

0 个答案:

没有答案
相关问题