Merge branch 'master' of https://github.com/benoitc/gunicorn into statsd-logger

This commit is contained in:
Alexis Le-Quoc 2014-05-30 23:10:35 -04:00
commit de9b05c774
21 changed files with 120 additions and 175 deletions

9
.gitignore vendored
View File

@ -2,6 +2,9 @@
*.sw* *.sw*
*.pyc *.pyc
*#* *#*
venv*
__pycache__
MANIFEST
build build
dist dist
setuptools-* setuptools-*
@ -14,12 +17,6 @@ distribute-0.6.8.tar.gz
gunicorn.egg-info gunicorn.egg-info
nohup.out nohup.out
.coverage .coverage
doc/.sass-cache
bin/
lib/
man/
include/
html/
examples/frameworks/pylonstest/PasteScript* examples/frameworks/pylonstest/PasteScript*
examples/frameworks/pylonstest/pylonstest.egg-info/ examples/frameworks/pylonstest/pylonstest.egg-info/
examples/frameworks/django/testing/testdb.sql examples/frameworks/django/testing/testdb.sql

View File

@ -3,9 +3,10 @@ python:
- "2.6" - "2.6"
- "2.7" - "2.7"
- "3.3" - "3.3"
- "3.4"
- "pypy" - "pypy"
install: install:
- "pip install -r requirements_dev.txt --use-mirrors" - "pip install -r requirements_dev.txt"
- "python setup.py install" - "python setup.py install"
script: py.test -x tests/ script: py.test -x tests/
branches: branches:

View File

@ -1,13 +1,17 @@
build: build:
virtualenv --no-site-packages . virtualenv venv
bin/python setup.py develop venv/bin/pip install -e .
bin/pip install -r requirements_dev.txt venv/bin/pip install -r requirements_dev.txt
test: test:
bin/python setup.py test venv/bin/python setup.py test
coverage: coverage:
bin/python setup.py test --cov venv/bin/python setup.py test --cov
clean: clean:
@rm -rf .Python bin lib include man build html @rm -rf .Python MANIFEST build dist venv* *.egg-info
@find . -type f -name "*.py[co]" -delete
@find . -type d -name "__pycache__" -delete
.PHONY: build clean coverage test

View File

@ -23,7 +23,7 @@ Changelog - 2012
- **Added support for Python 3.2 & 3.3** - **Added support for Python 3.2 & 3.3**
- Expose --pythonpath command to all gunicorn commands - Expose --pythonpath command to all gunicorn commands
- Honor $PORT environment variable, useful for deployement on heroku - Honor $PORT environment variable, useful for deployment on heroku
- Removed support for Python 2.5 - Removed support for Python 2.5
- Make sure we reopen the logs on the console - Make sure we reopen the logs on the console
- Fix django settings module detection from path - Fix django settings module detection from path
@ -82,7 +82,7 @@ Changelog - 2012
- improvement: performance of http.body.Body.readline() - improvement: performance of http.body.Body.readline()
- improvement: log HTTP errors in access log like Apache - improvement: log HTTP errors in access log like Apache
- improvment: display traceback when the worker fails to boot - improvement: display traceback when the worker fails to boot
- improvement: makes gunicorn work with gevent 1.0 - improvement: makes gunicorn work with gevent 1.0
- examples: websocket example now supports hybi13 - examples: websocket example now supports hybi13
- fix: reopen log files after initialization - fix: reopen log files after initialization

View File

@ -64,17 +64,7 @@ For instance::
bind = "127.0.0.1:8000" bind = "127.0.0.1:8000"
workers = multiprocessing.cpu_count() * 2 + 1 workers = multiprocessing.cpu_count() * 2 + 1
On a side note, Python's older than 2.6 can use sysconf to get the All the settings are mentioned in the :ref:`settings <settings>` list.
number of processors::
import os
def numCPUs():
if not hasattr(os, "sysconf"):
raise RuntimeError("No sysconf detected.")
return os.sysconf("SC_NPROCESSORS_ONLN")
All the settings are mentionned in the :ref:`settings <settings>` list.
Framework Settings Framework Settings

View File

@ -77,7 +77,7 @@ To turn off buffering, you only need to add ``proxy_buffering off;`` to your
``location`` block:: ``location`` block::
... ...
location / { location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_redirect off; proxy_redirect off;
@ -169,7 +169,7 @@ Create a ``Procfile`` in your project::
gunicorn = gunicorn -w 3 test:app gunicorn = gunicorn -w 3 test:app
You can any other applications that should be launched at the same time. You can launch any other applications that should be launched at the same time.
Then you can start your gunicorn application using `gaffer <http://gaffer.readthedocs.org/en/latest/gaffer.html>`_.:: Then you can start your gunicorn application using `gaffer <http://gaffer.readthedocs.org/en/latest/gaffer.html>`_.::

View File

@ -2,65 +2,26 @@
Installation Installation
============ ============
Follow the following steps to install Gunicorn. .. highlight:: bash
Requirements :Requirements: **Python 2.x >= 2.6** or **Python 3.x >= 3.1**
============
- **Python 2.x >= 2.6** or **Python 3.x >= 3.1** To install the latest released version of Gunicorn::
- setuptools >= 0.6c6
- nosetests (for the test suite only)
With easy_install $ pip install gunicorn
=================
If you don't already have ``easy_install`` available you'll want to download
and run the ``ez_setup.py`` script::
$ curl -O http://peak.telecommunity.com/dist/ez_setup.py
$ sudo python ez_setup.py -U setuptools
To install or upgrade to the latest released version of Gunicorn::
$ sudo easy_install -U gunicorn
.. note::
There is a limited support version of Gunicorn that is compatible
with Python 2.4. This fork is managed by Randall Leeds and can be
found `here on github`_. To install this version you must specify
the full url to something like ``pip``. This hasn't been tested
wtih ``easy_install`` just yet::
$ pip install -f http://github.com/tilgovi/gunicorn/tarball/py24 gunicorn
From Source From Source
=========== ===========
You can install Gunicorn from source just as you would install any other You can install Gunicorn from source just as you would install any other
Python package. Gunicorn uses setuptools which will automatically fetch all Python package::
dependencies (including setuptools itself).
You can download a tarball of the latest sources from `GitHub Downloads`_ or $ pip install git+https://github.com/benoitc/gunicorn.git
fetch them with git_::
# Using git: This will allow you to keep up to date with development on GitHub::
$ git clone git://github.com/benoitc/gunicorn.git
$ cd gunicorn
# Or using a tarball: $ pip install -U git+https://github.com/benoitc/gunicorn.git
$ wget http://github.com/benoitc/gunicorn/tarball/master -o gunicorn.tar.gz
$ tar -xvzf gunicorn.tar.gz
$ cd gunicorn-$HASH/
# Install
$ sudo python setup.py install
If you've cloned the git repository, its highly recommended that you use the
``develop`` command which will allow you to use Gunicorn from the source
directory. This will allow you to keep up to date with development on GitHub as
well as make changes to the source::
$ python setup.py develop
Async Workers Async Workers
============= =============
@ -72,9 +33,9 @@ want to consider one of the alternate worker types.
:: ::
$ easy_install -U greenlet # Required for both $ pip install greenlet # Required for both
$ easy_install -U eventlet # For eventlet workers $ pip install eventlet # For eventlet workers
$ easy_install -U gevent # For gevent workers $ pip install gevent # For gevent workers
.. note:: .. note::
If installing ``greenlet`` fails you probably need to install If installing ``greenlet`` fails you probably need to install
@ -87,6 +48,7 @@ want to consider one of the alternate worker types.
package manager. If Gevent_ fails to build even with libevent_ package manager. If Gevent_ fails to build even with libevent_
installed, this is the most likely reason. installed, this is the most likely reason.
Debian GNU/Linux Debian GNU/Linux
================ ================
@ -95,22 +57,22 @@ system packages to install Gunicorn except maybe when you want to use
different versions of gunicorn with virtualenv. This has a number of different versions of gunicorn with virtualenv. This has a number of
advantages: advantages:
* Zero-effort installation: Automatically starts multiple Gunicorn instances * Zero-effort installation: Automatically starts multiple Gunicorn instances
based on configurations defined in ``/etc/gunicorn.d``. based on configurations defined in ``/etc/gunicorn.d``.
* Sensible default locations for logs (``/var/log/gunicorn``). Logs * Sensible default locations for logs (``/var/log/gunicorn``). Logs
can be automatically rotated and compressed using ``logrotate``. can be automatically rotated and compressed using ``logrotate``.
* Improved security: Can easily run each Gunicorn instance with a dedicated * Improved security: Can easily run each Gunicorn instance with a dedicated
UNIX user/group. UNIX user/group.
* Sensible upgrade path: Upgrades to newer versions result in less downtime, * Sensible upgrade path: Upgrades to newer versions result in less downtime,
handle conflicting changes in configuration options, and can be quickly handle conflicting changes in configuration options, and can be quickly
rolled back in case of incompatibility. The package can also be purged rolled back in case of incompatibility. The package can also be purged
entirely from the system in seconds. entirely from the system in seconds.
Stable ("wheezy") Stable ("wheezy")
------------------ -----------------
The version of Gunicorn in the Debian_ "stable" distribution is 0.14.5 (June The version of Gunicorn in the Debian_ "stable" distribution is 0.14.5 (June
2012). You can install it using:: 2012). You can install it using::
@ -166,6 +128,8 @@ our PPA_ by adding ``ppa:gunicorn/ppa`` to your system's Software
Sources. Use the ``apt-add-repository`` command from the Sources. Use the ``apt-add-repository`` command from the
``python-software-properties`` package to add the Gunicorn software source. ``python-software-properties`` package to add the Gunicorn software source.
::
$ sudo apt-add-repository ppa:gunicorn/ppa $ sudo apt-add-repository ppa:gunicorn/ppa
Or this PPA can be added to your system manually by copying the lines below Or this PPA can be added to your system manually by copying the lines below
@ -174,27 +138,14 @@ and adding them to your system's software sources::
deb http://ppa.launchpad.net/gunicorn/ppa/ubuntu lucid main deb http://ppa.launchpad.net/gunicorn/ppa/ubuntu lucid main
deb-src http://ppa.launchpad.net/gunicorn/ppa/ubuntu lucid main deb-src http://ppa.launchpad.net/gunicorn/ppa/ubuntu lucid main
Replace 'lucid' with your Ubuntu distribution series. Replace *lucid* with your Ubuntu distribution series.
Signing key :Signing key: ``1024R/5370FF2A``
----------- :Fingerprint: ``FC7B41B54C9B8476D9EC22A2C6773E575370FF2A``
::
1024R/5370FF2A
Fingerprint
-----------
::
FC7B41B54C9B8476D9EC22A2C6773E575370FF2A
.. _`GitHub Downloads`: http://github.com/benoitc/gunicorn/downloads
.. _`design docs`: design.html .. _`design docs`: design.html
.. _git: http://git-scm.com/
.. _Eventlet: http://eventlet.net .. _Eventlet: http://eventlet.net
.. _`here on github`: http://github.com/tilgovi/gunicorn
.. _Gevent: http://gevent.org .. _Gevent: http://gevent.org
.. _libevent: http://monkey.org/~provos/libevent .. _libevent: http://monkey.org/~provos/libevent
.. _Debian: http://www.debian.org/ .. _Debian: http://www.debian.org/

View File

@ -116,7 +116,7 @@ service release.
- **Added support for Python 3.2 & 3.3** - **Added support for Python 3.2 & 3.3**
- Expose --pythonpath command to all gunicorn commands - Expose --pythonpath command to all gunicorn commands
- Honor $PORT environment variable, useful for deployement on heroku - Honor $PORT environment variable, useful for deployment on heroku
- Removed support for Python 2.5 - Removed support for Python 2.5
- Make sure we reopen the logs on the console - Make sure we reopen the logs on the console
- Fix django settings module detection from path - Fix django settings module detection from path
@ -175,7 +175,7 @@ service release.
- improvement: performance of http.body.Body.readline() - improvement: performance of http.body.Body.readline()
- improvement: log HTTP errors in access log like Apache - improvement: log HTTP errors in access log like Apache
- improvment: display traceback when the worker fails to boot - improvement: display traceback when the worker fails to boot
- improvement: makes gunicorn work with gevent 1.0 - improvement: makes gunicorn work with gevent 1.0
- examples: websocket example now supports hybi13 - examples: websocket example now supports hybi13
- fix: reopen log files after initialization - fix: reopen log files after initialization

View File

@ -73,6 +73,9 @@ A positive integer generally in the 2-4 x $(NUM_CORES) range. You'll
want to vary this a bit to find the best for your particular want to vary this a bit to find the best for your particular
application's work load. application's work load.
By default, the value of the WEB_CONCURRENCY environment variable. If
it is not defined, the default is 1.
worker_class worker_class
~~~~~~~~~~~~ ~~~~~~~~~~~~
@ -215,8 +218,10 @@ debug
* ``--debug`` * ``--debug``
* ``False`` * ``False``
**DEPRECATED**: This no functionality was removed after v18.0. This Turn on debugging in the server.
option is now a no-op.
**DEPRECATED**: This no functionality was removed after v18.0.
This option is now a no-op.
reload reload
~~~~~~ ~~~~~~
@ -421,28 +426,27 @@ access_log_format
* ``--access-logformat STRING`` * ``--access-logformat STRING``
* ``%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"`` * ``%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"``
The Access log format . The access log format.
By default: ========== ===========
Identifier Description
%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" ========== ===========
h remote address
l '-'
| h: remote address u currently '-', may be user name in future releases
| l: '-' t date of the request
| u: currently '-', may be user name in future releases r status line (e.g. ``GET / HTTP/1.1``)
| t: date of the request s status
| r: status line (ex: GET / HTTP/1.1) b response length or '-'
| s: status f referer
| b: response length or '-' a user agent
| f: referer T request time in seconds
| a: user agent D request time in microseconds
| T: request time in seconds L request time in decimal seconds
| D: request time in microseconds p process ID
| L: request time in decimal seconds {Header}i request header
| p: process ID {Header}o response header
| {Header}i: request header ========== ===========
| {Header}o: response header
errorlog errorlog
~~~~~~~~ ~~~~~~~~
@ -610,10 +614,15 @@ e.g.
paste paste
~~~~~ ~~~~~
* ``--paster STRING`` * ``--paste STRING, --paster STRING``
* ``None`` * ``None``
Load a paste.deploy config file. Load a paste.deploy config file. The argument may contain a "#" symbol
followed by the name of an app section from the config file, e.g.
"production.ini#admin".
At this time, using alternate server blocks is not supported. Use the
command line arguments to control server configuration instead.
Server Hooks Server Hooks
------------ ------------

View File

@ -35,8 +35,8 @@ Sending signals directly to the worker processes should not normally be
needed. If the master process is running, any exited worker will be needed. If the master process is running, any exited worker will be
automatically respawned. automatically respawned.
- **QUIT**, **INT**: Graceful shutdown - **QUIT**, **INT**: Quick shutdown
- **TERM**: Quick shutdown - **TERM**: Graceful shutdown
- **USR1**: Reopen the log files - **USR1**: Reopen the log files
Reload the configuration Reload the configuration

View File

@ -86,6 +86,11 @@ http {
root /path/to/app/current/public; root /path/to/app/current/public;
location / { location / {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
# an HTTP header important enough to have its own Wikipedia entry: # an HTTP header important enough to have its own Wikipedia entry:
# http://en.wikipedia.org/wiki/X-Forwarded-For # http://en.wikipedia.org/wiki/X-Forwarded-For
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

View File

@ -3,8 +3,6 @@
# This file is part of gunicorn released under the MIT license. # This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information. # See the NOTICE for more information.
from __future__ import with_statement
import errno import errno
import os import os
import random import random
@ -336,9 +334,9 @@ class Arbiter(object):
killed gracefully (ie. trying to wait for the current connection) killed gracefully (ie. trying to wait for the current connection)
""" """
self.LISTENERS = [] self.LISTENERS = []
sig = signal.SIGQUIT sig = signal.SIGTERM
if not graceful: if not graceful:
sig = signal.SIGTERM sig = signal.SIGQUIT
limit = time.time() + self.cfg.graceful_timeout limit = time.time() + self.cfg.graceful_timeout
while self.WORKERS and time.time() < limit: while self.WORKERS and time.time() < limit:
self.kill_workers(sig) self.kill_workers(sig)

View File

@ -434,6 +434,7 @@ def get_default_config_file():
return None return None
# Please remember to run "make html" in docs/ after update "desc" attributes.
class ConfigFile(Setting): class ConfigFile(Setting):
name = "config" name = "config"
section = "Config File" section = "Config File"
@ -536,7 +537,7 @@ class WorkerClass(Setting):
* ``sync`` * ``sync``
* ``eventlet`` - Requires eventlet >= 0.9.7 * ``eventlet`` - Requires eventlet >= 0.9.7
* ``gevent`` - Requires gevent >= 0.12.2 (?) * ``gevent`` - Requires gevent >= 0.13
* ``tornado`` - Requires tornado >= 0.2 * ``tornado`` - Requires tornado >= 0.2
Optionally, you can provide your own worker by giving gunicorn a Optionally, you can provide your own worker by giving gunicorn a
@ -808,7 +809,7 @@ class Env(Setting):
$ gunicorn -b 127.0.0.1:8000 --env FOO=1 test:app $ gunicorn -b 127.0.0.1:8000 --env FOO=1 test:app
and test for the foo variable environement in your application. and test for the foo variable environment in your application.
""" """
@ -971,27 +972,27 @@ class AccessLogFormat(Setting):
validator = validate_string validator = validate_string
default = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' default = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
desc = """\ desc = """\
The Access log format . The access log format.
By default: ========== ===========
Identifier Description
%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" ========== ===========
h remote address
l '-'
| h: remote address u currently '-', may be user name in future releases
| l: '-' t date of the request
| u: currently '-', may be user name in future releases r status line (e.g. ``GET / HTTP/1.1``)
| t: date of the request s status
| r: status line (ex: GET / HTTP/1.1) b response length or '-'
| s: status f referer
| b: response length or '-' a user agent
| f: referer T request time in seconds
| a: user agent D request time in microseconds
| T: request time in seconds L request time in decimal seconds
| D: request time in microseconds, p process ID
| p: process ID {Header}i request header
| {Header}i: request header {Header}o response header
| {Header}o: response header ========== ===========
""" """

View File

@ -84,7 +84,7 @@ class SafeAtoms(dict):
def __init__(self, atoms): def __init__(self, atoms):
dict.__init__(self) dict.__init__(self)
for key, value in atoms.items(): for key, value in atoms.items():
if isinstance(value, basestring): if isinstance(value, string_types):
self[key] = value.replace('"', '\\"') self[key] = value.replace('"', '\\"')
else: else:
self[key] = value self[key] = value

View File

@ -3,8 +3,6 @@
# This file is part of gunicorn released under the MIT license. # This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information. # See the NOTICE for more information.
from __future__ import with_statement
import errno import errno
import os import os
import tempfile import tempfile

View File

@ -3,8 +3,6 @@
# This file is part of gunicorn released under the MIT license. # This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information. # See the NOTICE for more information.
from __future__ import with_statement
import errno import errno
import os import os
import sys import sys

View File

@ -10,10 +10,8 @@ import tempfile
from gunicorn import util from gunicorn import util
PLATFORM = platform.system() PLATFORM = platform.system()
if PLATFORM.startswith('CYGWIN'): IS_CYGWIN = PLATFORM.startswith('CYGWIN')
IS_CYGWIN = True
else:
IS_CYGWIN = False
class WorkerTmp(object): class WorkerTmp(object):

View File

@ -24,6 +24,7 @@ CLASSIFIERS = [
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Internet', 'Topic :: Internet',
'Topic :: Utilities', 'Topic :: Utilities',
'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Software Development :: Libraries :: Python Modules',

View File

@ -4,8 +4,6 @@
# This file is part of gunicorn released under the MIT license. # This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information. # See the NOTICE for more information.
from __future__ import with_statement
import array import array
import os import os
import tempfile import tempfile

View File

@ -3,8 +3,6 @@
# This file is part of gunicorn released under the MIT license. # This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information. # See the NOTICE for more information.
from __future__ import with_statement
import t import t
import functools import functools

View File

@ -3,8 +3,6 @@
# This file is part of the pywebmachine package released # This file is part of the pywebmachine package released
# under the MIT license. # under the MIT license.
from __future__ import with_statement
import t import t
import inspect import inspect