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

Deprecate gaiohttp worker and document alternatives #1569

Merged
merged 2 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 21 additions & 1 deletion docs/source/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ There's also a Tornado worker class. It can be used to write applications using
the Tornado framework. Although the Tornado workers are capable of serving a
WSGI application, this is not a recommended configuration.


.. _asyncio-workers:

AsyncIO Workers
---------------

Expand All @@ -66,6 +69,21 @@ the connection is closed.

The worker `gaiohttp` is a full asyncio worker using aiohttp_.

.. note::
The ``gaiohttp`` worker requires the aiohttp_ module to be installed.
aiohttp_ has removed its native WSGI application support in version 2.
If you want to continue to use the ``gaiohttp`` worker with your WSGI
application (e.g. an application that uses Flask or Django), there are
three options available:

#. Install aiohttp_ version 1.3.5 instead of version 2::

$ pip install aiohttp==1.3.5

#. Use aiohttp_wsgi_ to wrap your WSGI application. You can take a look
at the `example`_ in the Gunicorn repository.
#. Port your application to use aiohttp_'s ``web.Application`` API.

Choosing a Worker Type
======================

Expand Down Expand Up @@ -137,4 +155,6 @@ code in the master process).
.. _Eventlet: http://eventlet.net
.. _Gevent: http://gevent.org
.. _Hey: https://github.com/rakyll/hey
.. _aiohttp: https://github.com/KeepSafe/aiohttp
.. _aiohttp: https://aiohttp.readthedocs.io/en/stable/
.. _aiohttp_wsgi: https://aiohttp-wsgi.readthedocs.io/en/stable/index.html
.. _`example`: https://github.com/benoitc/gunicorn/blob/master/examples/frameworks/flaskapp_aiohttp_wsgi.py
6 changes: 6 additions & 0 deletions docs/source/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

19.8.0 / not released
=====================

- :pr:`1569`, :pr:`1418` and :issue:`1338`: The ``gaiohttp`` worker is
deprecated. See the :ref:`worker-class` documentation for more information.

19.7.1 / 2017/03/21
===================

Expand Down
6 changes: 4 additions & 2 deletions docs/source/run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ Commonly Used Arguments
* ``-k WORKERCLASS, --worker-class=WORKERCLASS`` - The type of worker process
to run. You'll definitely want to read the production page for the
implications of this parameter. You can set this to ``$(NAME)``
where ``$(NAME)`` is one of ``sync``, ``eventlet``, ``gevent``, or
``tornado``, ``gthread``, ``gaiohttp``. ``sync`` is the default.
where ``$(NAME)`` is one of ``sync``, ``eventlet``, ``gevent``,
``tornado``, ``gthread``, ``gaiohttp`` (deprecated in Gunicorn 19.8).
``sync`` is the default. See the :ref:`worker-class` documentation for more
information.
* ``-n APP_NAME, --name=APP_NAME`` - If setproctitle_ is installed you can
adjust the name of Gunicorn process as they appear in the process system
table (which affects tools like ``ps`` and ``top``).
Expand Down
9 changes: 8 additions & 1 deletion docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,20 @@ A string referring to one of the following bundled classes:
* ``gevent`` - Requires gevent >= 0.13
* ``tornado`` - Requires tornado >= 0.2
* ``gthread`` - Python 2 requires the futures package to be installed
* ``gaiohttp`` - Requires Python 3.4 and aiohttp >= 0.21.5
* ``gaiohttp`` - Deprecated. Please use
Copy link
Owner

@benoitc benoitc Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should just mark it as deprecated. documentation is already here to point to external asyncio workers. "The 'gaiohttp' worker is deprecated. Please look at "link to worker page" for an alternative worker supporting asyncio."

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man, i just started using it this week! :)

``aiohttp.worker.GunicornWebWorker`` instead. See :ref:`asyncio-workers`
for more information on how to use it.

Optionally, you can provide your own worker by giving Gunicorn a
Python path to a subclass of ``gunicorn.workers.base.Worker``.
This alternative syntax will load the gevent class:
``gunicorn.workers.ggevent.GeventWorker``.

.. deprecated:: 19.8
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

The ``gaiohttp`` worker is deprecated. Please use
``aiohttp.worker.GunicornWebWorker`` instead. See
:ref:`asyncio-workers` for more information on how to use it.

.. _threads:

threads
Expand Down
24 changes: 24 additions & 0 deletions examples/frameworks/flaskapp_aiohttp_wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Example command to run the example:
#
# $ gunicorn flaskapp_aiohttp_wsgi:aioapp -k aiohttp.worker.GunicornWebWorker
#

from aiohttp import web
from aiohttp_wsgi import WSGIHandler
from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello():
return 'Hello, world!'


def make_aiohttp_app(app):
wsgi_handler = WSGIHandler(app)
aioapp = web.Application()
aioapp.router.add_route('*', '/{path_info:.*}', wsgi_handler)
return aioapp

aioapp = make_aiohttp_app(app)
9 changes: 8 additions & 1 deletion gunicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,19 @@ class WorkerClass(Setting):
* ``gevent`` - Requires gevent >= 0.13
* ``tornado`` - Requires tornado >= 0.2
* ``gthread`` - Python 2 requires the futures package to be installed
* ``gaiohttp`` - Requires Python 3.4 and aiohttp >= 0.21.5
* ``gaiohttp`` - Deprecated. Please use
``aiohttp.worker.GunicornWebWorker`` instead. See :ref:`asyncio-workers`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem. just tell it's deprecated.

for more information on how to use it.

Optionally, you can provide your own worker by giving Gunicorn a
Python path to a subclass of ``gunicorn.workers.base.Worker``.
This alternative syntax will load the gevent class:
``gunicorn.workers.ggevent.GeventWorker``.

.. deprecated:: 19.8
The ``gaiohttp`` worker is deprecated. Please use
``aiohttp.worker.GunicornWebWorker`` instead. See
:ref:`asyncio-workers` for more information on how to use it.
"""

class WorkerThreads(Setting):
Expand Down
16 changes: 13 additions & 3 deletions gunicorn/workers/gaiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@

import sys

if sys.version_info >= (3, 3):
from gunicorn import util

if sys.version_info >= (3, 4):
try:
import aiohttp # NOQA
except ImportError:
raise RuntimeError("You need aiohttp installed to use this worker.")
else:
from gunicorn.workers._gaiohttp import AiohttpWorker
try:
from aiohttp.worker import GunicornWebWorker as AiohttpWorker
except ImportError:
from gunicorn.workers._gaiohttp import AiohttpWorker

util.warn(
Copy link
Contributor

@Code0x58 Code0x58 Sep 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this kind of thing should be using Python's inbuilt warning logging facilities, with a DeprecationWarning. This may be a separarte issue if there are other similar depreciation warnings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made #1590/#1591 to use warnings in the other two places.

"The 'gaiohttp' worker is deprecated. Please install 'aiohttp' "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would would reformulate by saying that "The 'gaiohttp' worker is deprecated. Please look at "link to worker page" for an alternative worker supporting asyncio.

"and pass 'aiohttp.worker.GunicornWebWorker' to --worker-class."
)
__all__ = ['AiohttpWorker']
else:
raise RuntimeError("You need Python >= 3.3 to use the asyncio worker")
raise RuntimeError("You need Python >= 3.4 to use the gaiohttp worker")