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

gevent monkey patch before any other imports #1828

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1168,11 +1168,11 @@ libraries may be installed using setuptools' ``extra_require`` feature.
A string referring to one of the following bundled classes:

* ``sync``
* ``eventlet`` - Requires eventlet >= 0.9.7 (or install it via
* ``eventlet`` - Requires eventlet >= 0.9.7 (or install it via
``pip install gunicorn[eventlet]``)
* ``gevent`` - Requires gevent >= 0.13 (or install it via
* ``gevent`` - Requires gevent >= 1.0 (or install it via
``pip install gunicorn[gevent]``)
* ``tornado`` - Requires tornado >= 0.2 (or install it via
* ``tornado`` - Requires tornado >= 0.2 (or install it via
``pip install gunicorn[tornado]``)
* ``gthread`` - Python 2 requires the futures package to be installed
(or install it via ``pip install gunicorn[gthread]``)
Expand Down
8 changes: 4 additions & 4 deletions gunicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,11 @@ class WorkerClass(Setting):
A string referring to one of the following bundled classes:

* ``sync``
* ``eventlet`` - Requires eventlet >= 0.9.7 (or install it via
* ``eventlet`` - Requires eventlet >= 0.9.7 (or install it via
``pip install gunicorn[eventlet]``)
* ``gevent`` - Requires gevent >= 0.13 (or install it via
* ``gevent`` - Requires gevent >= 1.0 (or install it via
``pip install gunicorn[gevent]``)
* ``tornado`` - Requires tornado >= 0.2 (or install it via
* ``tornado`` - Requires tornado >= 0.2 (or install it via
``pip install gunicorn[tornado]``)
* ``gthread`` - Python 2 requires the futures package to be installed
(or install it via ``pip install gunicorn[gthread]``)
Expand Down Expand Up @@ -652,7 +652,7 @@ class WorkerThreads(Setting):
If it is not defined, the default is ``1``.

This setting only affects the Gthread worker type.

.. note::
If you try to use the ``sync`` worker type and set the ``threads``
setting to more than 1, the ``gthread`` worker type will be used
Expand Down
20 changes: 6 additions & 14 deletions gunicorn/workers/ggevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
os.environ['EVENT_NOKQUEUE'] = "1"

try:
import gevent
from gevent import monkey

monkey.patch_all(subprocess=True)
except ImportError:
raise RuntimeError("You need gevent installed to use this worker.")

import gevent
from gevent.pool import Pool
from gevent.server import StreamServer
from gevent.socket import wait_write, socket
Expand Down Expand Up @@ -55,15 +59,6 @@ class GeventWorker(AsyncWorker):
wsgi_handler = None

def patch(self):
from gevent import monkey
monkey.noisy = False

# if the new version is used make sure to patch subprocess
if gevent.version_info[0] == 0:
monkey.patch_all()
else:
monkey.patch_all(subprocess=True)

# monkey patch sendfile to make it none blocking
patch_sendfile()

Expand Down Expand Up @@ -121,10 +116,7 @@ def run(self):
try:
# Stop accepting requests
for server in servers:
if hasattr(server, 'close'): # gevent 1.0
server.close()
if hasattr(server, 'kill'): # gevent < 1.0
server.kill()
server.close()

# Handle current requests until graceful_timeout
ts = time.time()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def run_tests(self):


extra_require = {
'gevent': ['gevent>=0.13'],
'gevent': ['gevent>=1.0'],
'eventlet': ['eventlet>=0.9.7'],
'tornado': ['tornado>=0.2'],
'gthread': [],
Expand Down