忍不住直接部署这基础的程序,不学了,先部署
安装gunicorn
$ pip install gunicorn
一阵下载,安装,完成
启动服务
$ gunicorn -w 4 -b 127.0.0.1:4000 app:app
[2020-02-17 11:47:13 +0800] [28462] [INFO] Starting gunicorn 20.0.4
[2020-02-17 11:47:13 +0800] [28462] [INFO] Listening at: http://127.0.0.1:4000 (28462)
[2020-02-17 11:47:13 +0800] [28462] [INFO] Using worker: sync
[2020-02-17 11:47:13 +0800] [28465] [INFO] Booting worker with pid: 28465
[2020-02-17 11:47:13 +0800] [28466] [INFO] Booting worker with pid: 28466
[2020-02-17 11:47:13 +0800] [28467] [INFO] Booting worker with pid: 28467
[2020-02-17 11:47:13 +0800] [28469] [INFO] Booting worker with pid: 28469
^C[2020-02-17 11:47:59 +0800] [28462] [INFO] Handling signal: int
这样就起来了,跟flask run貌似没啥区别,只是可以配置起多个并发吧。
通过配置后台启动
在config.py中新增配置项
import multiprocessing
#...
## for gunicorn
debug = True
loglevel = 'debug'
bind = '0.0.0.0:5000'
pidfile = 'log/gunicorn.pid'
accesslog = 'log/access.log'# log目录必需存在
errorlog = 'log/error.log'
daemon = True
workers = multiprocessing.cpu_count()
重新启动服务器
$ gunicorn --config=config.py app:app
这样就后台启动了。。。。
貌似可以不再使用nohup flask run & 后台启动python服务了,一大改观!
关闭服务器
...怎么关闭啊! 从pid文件中读取pid kill吗??