gunicorn运行显示connection in use解决办法

运行gunicorn后显示如下错误:

root@iZ2ze2gihbn4ot85zlcdxdZ:~/myproject# gunicorn -w 4 -b 0.0.0.0:5000 myapp:app
[2018-03-16 15:48:33 +0800] [9555] [INFO] Starting gunicorn 19.7.1
[2018-03-16 15:48:33 +0800] [9555] [ERROR] Connection in use: ('0.0.0.0', 5000)
[2018-03-16 15:48:33 +0800] [9555] [ERROR] Retrying in 1 second.
[2018-03-16 15:48:34 +0800] [9555] [ERROR] Connection in use: ('0.0.0.0', 5000)
[2018-03-16 15:48:34 +0800] [9555] [ERROR] Retrying in 1 second.
[2018-03-16 15:48:35 +0800] [9555] [ERROR] Connection in use: ('0.0.0.0', 5000)
[2018-03-16 15:48:35 +0800] [9555] [ERROR] Retrying in 1 second.
[2018-03-16 15:48:36 +0800] [9555] [ERROR] Connection in use: ('0.0.0.0', 5000)
[2018-03-16 15:48:36 +0800] [9555] [ERROR] Retrying in 1 second.
[2018-03-16 15:48:37 +0800] [9555] [ERROR] Connection in use: ('0.0.0.0', 5000)
[2018-03-16 15:48:37 +0800] [9555] [ERROR] Retrying in 1 second.
[2018-03-16 15:48:38 +0800] [9555] [ERROR] Can't connect to ('0.0.0.0', 5000)

  显示正在运行的gunicorn进程,发现没有已经运行zai 0.0.0.0:5000的进程:

root@iZ2ze2gihbn4ot85zlcdxdZ:~/myproject# pstree -ap|grep gunicorn
  |                           |-grep,9539 --color=auto gunicorn

这时查看服务器(主机)运行的全部进程:

root@iZ2ze2gihbn4ot85zlcdxdZ:~/myproject# ps -a
  PID TTY          TIME CMD
 9446 pts/0    00:00:00 su
 9447 pts/0    00:00:00 bash
 9488 pts/0    00:00:00 sudo
 9489 pts/0    00:00:00 bash
 9514 pts/0    00:00:00 python3
 9516 pts/0    00:00:00 python3
 9551 pts/0    00:00:00 ps

  这时发现有两个python3的进程,其中有一个是运行的myapp.py文件的进程,而gunicorn要运行的就是该文件,因此产生冲突。

删掉进程:

root@iZ2ze2gihbn4ot85zlcdxdZ:~/myproject# kill -9 9516
[2]+  Killed                  python3 myapp.py

 这时再运行gunicorn就好了:

root@iZ2ze2gihbn4ot85zlcdxdZ:~/myproject# gunicorn -w 4 -b 0.0.0.0:5000 myapp:app
[2018-03-16 15:49:41 +0800] [9558] [INFO] Starting gunicorn 19.7.1
[2018-03-16 15:49:41 +0800] [9558] [INFO] Listening at: http://0.0.0.0:5000 (9558)
[2018-03-16 15:49:41 +0800] [9558] [INFO] Using worker: sync
[2018-03-16 15:49:41 +0800] [9561] [INFO] Booting worker with pid: 9561
[2018-03-16 15:49:41 +0800] [9563] [INFO] Booting worker with pid: 9563
[2018-03-16 15:49:41 +0800] [9564] [INFO] Booting worker with pid: 9564
[2018-03-16 15:49:42 +0800] [9565] [INFO] Booting worker with pid: 9565

  

 

posted @ 2018-03-16 16:01  IcarusYu  阅读(2184)  评论(0编辑  收藏  举报