Last active
April 29, 2019 07:10
-
-
Save suriya/1d9a11ea9ad33a5b1df0b2ba7ed0cd0e to your computer and use it in GitHub Desktop.
Demonstrating that Gunicorn does not respond immediately to SIGTERM (with Python 3.5)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The script run-and-stop-gunicorn.sh takes 1 second on both Python 2.7 and 3.4. | |
$ cat /etc/lsb-release | |
DISTRIB_ID=Ubuntu | |
DISTRIB_RELEASE=14.04 | |
DISTRIB_CODENAME=trusty | |
DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS" | |
$ | |
$ | |
$ source 27-env/bin/activate | |
(27-env)$ time ./run-and-stop-gunicorn.sh | |
[2016-05-09 17:07:16 +0000] [2735] [INFO] Starting gunicorn 19.4.5 | |
[2016-05-09 17:07:16 +0000] [2735] [INFO] Listening at: http://127.0.0.1:8000 (2735) | |
[2016-05-09 17:07:16 +0000] [2735] [INFO] Using worker: sync | |
[2016-05-09 17:07:16 +0000] [2741] [INFO] Booting worker with pid: 2741 | |
[2016-05-09 17:07:17 +0000] [2735] [INFO] Handling signal: term | |
[2016-05-09 17:07:17 +0000] [2741] [INFO] Worker exiting (pid: 2741) | |
[2016-05-09 17:07:17 +0000] [2735] [INFO] Shutting down: Master | |
real 0m1.043s | |
user 0m0.137s | |
sys 0m0.041s | |
(27-env)$ deactivate | |
$ | |
$ | |
$ source 34-env/bin/activate | |
(34-env)$ time ./run-and-stop-gunicorn.sh | |
[2016-05-09 17:07:31 +0000] [2763] [INFO] Starting gunicorn 19.4.5 | |
[2016-05-09 17:07:31 +0000] [2763] [INFO] Listening at: http://127.0.0.1:8000 (2763) | |
[2016-05-09 17:07:31 +0000] [2763] [INFO] Using worker: sync | |
[2016-05-09 17:07:31 +0000] [2767] [INFO] Booting worker with pid: 2767 | |
[2016-05-09 17:07:32 +0000] [2763] [INFO] Handling signal: term | |
[2016-05-09 17:07:32 +0000] [2767] [INFO] Worker exiting (pid: 2767) | |
[2016-05-09 17:07:32 +0000] [2763] [INFO] Shutting down: Master | |
real 0m1.096s | |
user 0m0.281s | |
sys 0m0.027s | |
(34-env)$ deactivate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bash session output. Notice that the script run-and-stop-gunicorn.sh | |
takes 1 second on Python 2.7, but takes 30 seconds on Python 3.5. | |
$ cat /etc/lsb-release | |
DISTRIB_ID=Ubuntu | |
DISTRIB_RELEASE=16.04 | |
DISTRIB_CODENAME=xenial | |
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS" | |
$ | |
$ | |
$ source 27-env/bin/activate | |
(27-env) $ python --version | |
Python 2.7.11+ | |
(27-env) $ gunicorn --version | |
gunicorn (version 19.4.5) | |
(27-env) $ time ./run-and-stop-gunicorn.sh | |
[2016-05-09 22:32:41 +0000] [12724] [INFO] Starting gunicorn 19.4.5 | |
[2016-05-09 22:32:41 +0000] [12724] [INFO] Listening at: http://127.0.0.1:8000 (12724) | |
[2016-05-09 22:32:41 +0000] [12724] [INFO] Using worker: sync | |
[2016-05-09 22:32:41 +0000] [12730] [INFO] Booting worker with pid: 12730 | |
[2016-05-09 22:32:42 +0000] [12724] [INFO] Handling signal: term | |
[2016-05-09 22:32:42 +0000] [12730] [INFO] Worker exiting (pid: 12730) | |
[2016-05-09 22:32:42 +0000] [12724] [INFO] Shutting down: Master | |
real 0m1.040s | |
user 0m0.200s | |
sys 0m0.020s | |
(27-env) $ deactivate | |
$ | |
$ | |
$ source 35-env/bin/activate | |
(35-env) $ python --version | |
Python 3.5.1+ | |
(35-env) $ gunicorn --version | |
gunicorn (version 19.4.5) | |
(35-env) $ time ./run-and-stop-gunicorn.sh | |
[2016-05-09 22:33:20 +0530] [12758] [INFO] Starting gunicorn 19.4.5 | |
[2016-05-09 22:33:20 +0530] [12758] [INFO] Listening at: http://127.0.0.1:8000 (12758) | |
[2016-05-09 22:33:20 +0530] [12758] [INFO] Using worker: sync | |
[2016-05-09 22:33:20 +0530] [12762] [INFO] Booting worker with pid: 12762 | |
[2016-05-09 22:33:21 +0530] [12758] [INFO] Handling signal: term | |
[2016-05-09 22:33:51 +0530] [12758] [INFO] Shutting down: Master | |
real 0m31.104s | |
user 0m0.280s | |
sys 0m0.028s | |
(35-env) $ deactivate | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def app(environ, start_response): | |
"""Simplest possible application object""" | |
data = b'Hello, World!\n' | |
status = '200 OK' | |
response_headers = [ | |
('Content-type','text/plain'), | |
('Content-Length', str(len(data))) | |
] | |
start_response(status, response_headers) | |
return iter([data]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
gunicorn --timeout 600 --pid gunicorn.pid myapp:app & | |
sleep 1 | |
kill -TERM `cat gunicorn.pid` | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment