1、代码如下:
print(__name__)
if __name__ == '__main__':
print('inner main')
app.run()
2、使用 uwsgi启动,打印出来的是:uwsgi_file__opt_main,不会执行app.run
/usr/local/python3/bin/uwsgi uwsgi.ini
控制台显示:
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x15ae5a0 pid: 9 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (pid: 9, cores: 2)
spawned uWSGI worker 2 (pid: 16, cores: 2)
3、使用python启动,打印出来的是:__main__以及inner main,执行了app.run,
python main.py
?执行到
cli.show_server_banner(self.env, self.debug, self.name, False)
控制台显示:
Serving Flask app "common" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
4、如果将'__main__'改为:'uwsgi_file__opt_main',并使用uwsgi方式启动
在linux控制台下,可以看到有两个端口占用,一个是uwsgi的,一个是app.run的默认5000端口
telnet localhost 8090
telnet localhost 5000
ctrl + ]
5、所以,需要初始化的代码,用uwsgi启动时,不要放在if __name__ = '__main__':下?
|