Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unblock the wait loop under python 3.5 #1257

Merged
merged 1 commit into from May 10, 2016
Merged

unblock the wait loop under python 3.5 #1257

merged 1 commit into from May 10, 2016

Conversation

benoitc
Copy link
Owner

@benoitc benoitc commented May 10, 2016

in python 3.5 the select is blocking when waiting for it which prevent quick
exit on SIGTERM.

The problem is described:
https://www.python.org/dev/peps/pep-0475/#backward-compatibility

This change fix it by listening for signal event on the worker pipe. Once an
event is triggered it will forcefully wake up the select and return.

fix #1256

in python 3.5 the select is blocking when waiting for it which prevent quick
exit on SIGTERM.

The problem is described:
https://www.python.org/dev/peps/pep-0475/#backward-compatibility

This change fix it by listening for signal event on the worker pipe. Once an
event is triggered it will forcefully wake up the select and return.

fix #1256
@aolefira
Copy link

In python 3.6 this bug appeared again

@benoitc
Copy link
Owner Author

benoitc commented Sep 29, 2017

@aolefira how do you produce it?

@aolefira
Copy link

aolefira commented Sep 29, 2017

I run script ./stop.sh with next content:
kill cat gunicorn.pid
and waiting a lot of seconds until gunicorn processes will be killed.
Software:
gunicorn 19.7.1
python 3.6.0
ubuntu 16.04.1 LTS
In settings worker_class = gthread
No '--timeout' argument used

@benoitc
Copy link
Owner Author

benoitc commented Sep 29, 2017 via email

@aolefira
Copy link

aolefira commented Sep 29, 2017

There are no records in logs while shutting down.

Command for start:
gunicorn --paste pyramid.ini --daemon

[server:main] part of pyramid.ini:
[server:main]
use = egg:gunicorn#main
host = 0.0.0.0
port = 6543
threads = 60
worker_class = gthread
errorlog = logs/error.log
loglevel = warning
capture_output = True
pidfile = gunicorn.pid
statsd_host = localhost:8125

Any pyramid project should be used.

To reproduce bug just enter:
kill ‵cat gunicorn.pid‵

@tilgovi
Copy link
Collaborator

tilgovi commented Sep 29, 2017

I cannot reproduce this.

MacOS X 10.13
Python 3.6.2
Gunicorn 19.7.1
Pyramid 1.9.1

Do you have a long connection open when you do this? What happens if you use kill -9?

@aolefira
Copy link

aolefira commented Oct 2, 2017

There are no long connections.
If kill -9 used, first process terminate, but second process remains hanging.

@aolefira
Copy link

aolefira commented Oct 2, 2017

Yes, on my macbook with MacOS X 10.11.6 this issue not reproduced too.
This issue reproduced on server with Ubuntu 16.04.1 LTS.

@aolefira
Copy link

aolefira commented Oct 2, 2017

Do you have a long connection open when you do this?

This bug reproduce (on Ubuntu 16.04.1) even if there are no connections.

@aolefira
Copy link

aolefira commented Oct 4, 2017

Problem is that pyramid runs thread at startup. In mac os x that thread die immediately on app shutdown but in ubuntu it's waiting for some time

@aolefira
Copy link

aolefira commented Oct 4, 2017

setDaemon(True) for threads resolve this problem

@tilgovi
Copy link
Collaborator

tilgovi commented Oct 4, 2017

What thread does Pyramid run at startup? I'm not aware of it doing that.

@tilgovi
Copy link
Collaborator

tilgovi commented Oct 4, 2017

As far as I know, the only thread Pyramid starts are started by pserve command, but you said you are using the gunicorn --paste command.

@aolefira
Copy link

aolefira commented Oct 5, 2017

What thread does Pyramid run at startup? I'm not aware of it doing that.

It's project specific threads. Two custom threads. First - scheduler and second - mailer.

@aolefira
Copy link

aolefira commented Oct 5, 2017

As far as I know, the only thread Pyramid starts are started by pserve command, but you said you are using the gunicorn --paste command.

pserve is good for development. but for production its better to use something more advanced, like gunicorn

https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/project.html#using-an-alternate-wsgi-server

https://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/deployment/gunicorn.html

@Dringho
Copy link

Dringho commented Feb 19, 2018

Also experiencing this bug on Ubuntu 16.04 / Python 3.5.2 / Gunicorn 19.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gunicorn doesn't shutdown immediately on receiving SIGTERM
4 participants