Skip to content

Commit

Permalink
The py24 for maintained as a single patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
davisp committed Aug 3, 2010
1 parent 1f598b9 commit cd5756f
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 135 deletions.
11 changes: 6 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ resource usage, and fairly speedy.

Feel free to join us in `#gunicorn`_ on freenode_.

This python 2.4 fork is maintained separately because it is not part of the
official distribution. It will not appear on pypi.

Installation
------------

Gunicorn requires **Python 2.x >= 2.5**. Python 3.x support is planned.

Install from sources::

$ python setup.py install

Or from Pypi::
Or from the Github tarball::

$ easy_install -U gunicorn
$ pip install -f http://github.com/tilgovi/gunicorn/tarball/py24 gunicorn

You may also want to install Eventlet_ or Gevent_ if you expect that your
application code may need to pause for extended periods of time during
Expand All @@ -28,7 +29,7 @@ want to consider one of the alternate worker types.

To install eventlet::

$ easy_install -U eventlet
$ pip install eventlet

If you encounter errors when compiling the extensions for Eventlet_ or
Gevent_ you most likely need to install a newer version of libev_.
Expand Down
32 changes: 17 additions & 15 deletions gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

from __future__ import with_statement

import errno
import logging
import os
Expand Down Expand Up @@ -145,7 +143,10 @@ def run(self):
while True:
try:
self.reap_workers()
sig = self.SIG_QUEUE.pop(0) if len(self.SIG_QUEUE) else None
if len(self.SIG_QUEUE):
sig = self.SIG_QUEUE.pop(0)
else:
sig = None
if sig is None:
self.sleep()
self.murder_workers()
Expand Down Expand Up @@ -422,18 +423,19 @@ def spawn_worker(self):
# Process Child
worker_pid = os.getpid()
try:
util._setproctitle("worker [%s]" % self.proc_name)
self.log.info("Booting worker with pid: %s" % worker_pid)
self.cfg.post_fork(self, worker)
worker.init_process()
sys.exit(0)
except SystemExit:
raise
except:
self.log.exception("Exception in worker process:")
if not worker.booted:
sys.exit(self.WORKER_BOOT_ERROR)
sys.exit(-1)
try:
util._setproctitle("worker [%s]" % self.proc_name)
self.log.info("Booting worker with pid: %s" % worker_pid)
self.cfg.post_fork(self, worker)
worker.init_process()
sys.exit(0)
except SystemExit:
raise
except:
self.log.exception("Exception in worker process:")
if not worker.booted:
sys.exit(self.WORKER_BOOT_ERROR)
sys.exit(-1)
finally:
self.log.info("Worker exiting (pid: %s)" % worker_pid)
try:
Expand Down
23 changes: 13 additions & 10 deletions gunicorn/http/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def parse_headers(self, data):
name, value = name.strip(), [value.lstrip()]

# Consume value continuation lines
while len(lines) and lines[0].startswith((" ", "\t")):
while len(lines) and (lines[0].startswith(" ") or lines[0].startswith("\t")):
value.append(lines.pop(0))
value = ''.join(value).rstrip()

Expand Down Expand Up @@ -167,17 +167,20 @@ def parse_request_line(self, line):

# URI
self.uri = bits[1]
parts = urlparse.urlparse(bits[1])
self.scheme = parts.scheme or ''
self.host = parts.netloc or None
if parts.port is None:
scheme, netloc, path, parameters, query, fragment = urlparse.urlparse(bits[1])
self.scheme = scheme or ''
self.host = netloc or ''

host_parts = self.host.rsplit(":", 1)

if len(host_parts) == 1:
self.port = 80
else:
self.host = self.host.rsplit(":", 1)[0]
self.port = parts.port
self.path = parts.path or ""
self.query = parts.query or ""
self.fragment = parts.fragment or ""
self.host = host_parts[0]
self.port = host_parts[1]
self.path = path or ""
self.query = query or ""
self.fragment = fragment or ""

# Version
match = self.versre.match(bits[2])
Expand Down
4 changes: 2 additions & 2 deletions gunicorn/http/unreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def read(self, size=None):
if size < 0:
size = None

self.buf.seek(0, os.SEEK_END)
self.buf.seek(0, 2)

if size is None and self.buf.tell():
ret = self.buf.getvalue()
Expand All @@ -50,7 +50,7 @@ def read(self, size=None):
return data[:size]

def unread(self, data):
self.buf.seek(0, os.SEEK_END)
self.buf.seek(0, 2)
self.buf.write(data)

class SocketUnreader(Unreader):
Expand Down
30 changes: 15 additions & 15 deletions gunicorn/pidfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

from __future__ import with_statement

import errno
import os
import tempfile
Expand Down Expand Up @@ -51,8 +49,9 @@ def rename(self, path):
def unlink(self):
""" delete pidfile"""
try:
with open(self.fname, "r") as f:
pid1 = int(f.read() or 0)
f = open(self.fname, "r")
pid1 = int(f.read() or 0)
f.close()

if pid1 == self.pid:
os.unlink(self.fname)
Expand All @@ -64,19 +63,20 @@ def validate(self):
if not self.fname:
return
try:
with open(self.fname, "r") as f:
wpid = int(f.read() or 0)
f = open(self.fname, "r")
wpid = int(f.read() or 0)
f.close()

if wpid <= 0:
return
if wpid <= 0:
return

try:
os.kill(wpid, 0)
return wpid
except OSError, e:
if e[0] == errno.ESRCH:
return
raise
try:
os.kill(wpid, 0)
return wpid
except OSError, e:
if e[0] == errno.ESRCH:
return
raise
except IOError, e:
if e[0] == errno.ENOENT:
return
Expand Down
57 changes: 29 additions & 28 deletions gunicorn/workers/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

from __future__ import with_statement

import errno
import socket
import traceback
Expand All @@ -27,34 +25,37 @@ def timeout_ctx(self):

def handle(self, client, addr):
try:
parser = http.RequestParser(client)
try:
while True:
req = None
with self.timeout_ctx():
req = parser.next()
if not req:
break
self.handle_request(req, client, addr)
except StopIteration:
pass
except socket.error, e:
if e[0] not in (errno.EPIPE, errno.ECONNRESET):
self.log.exception("Socket error processing request.")
else:
if e[0] == errno.ECONNRESET:
self.log.warn("Ignoring connection reset")
parser = http.RequestParser(client)
try:
while True:
timeout = self.timeout_ctx()
try:
req = parser.next()
finally:
timeout.cancel()
if not req:
break
self.handle_request(req, client, addr)
except StopIteration:
pass
except socket.error, e:
if e[0] not in (errno.EPIPE, errno.ECONNRESET):
self.log.exception("Socket error processing request.")
else:
self.log.debug("Ignoring EPIPE")
except Exception, e:
self.log.exception("General error processing request.")
try:
# Last ditch attempt to notify the client of an error.
mesg = "HTTP/1.0 500 Internal Server Error\r\n\r\n"
util.write_nonblock(client, mesg)
except:
pass
return
if e[0] == errno.ECONNRESET:
self.log.warn("Ignoring connection reset")
else:
self.log.debug("Ignoring EPIPE")
except Exception, e:
self.log.exception("General error processing request.")
try:
# Last ditch attempt to notify the client of an error.
mesg = "HTTP/1.0 500 Internal Server Error\r\n\r\n"
util.write_nonblock(client, mesg)
except:
pass
return
finally:
util.close(client)

Expand Down
14 changes: 8 additions & 6 deletions gunicorn/workers/geventlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

from __future__ import with_statement

import eventlet
import eventlet.debug

Expand Down Expand Up @@ -48,13 +46,17 @@ def run(self):
self.log.info("Parent changed, shutting down: %s" % self)
greenthread.kill(acceptor, eventlet.StopServe)
break

eventlet.sleep(0.1)

with eventlet.Timeout(self.timeout, False):
if pool.waiting():
timeout = eventlet.Timeout(self.timeout, False)
try:
try:
pool.waitall()

except eventlet.Timeout:
pass
finally:
timeout.cancel()
except KeyboardInterrupt:
pass

Expand Down
12 changes: 6 additions & 6 deletions gunicorn/workers/ggevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

from __future__ import with_statement

import os

Expand Down Expand Up @@ -83,11 +82,12 @@ def acceptor(self, pool):

def cleanup(self, gt):
try:
gt.join()
except greenlet.GreenletExit:
pass
except Exception:
self.log.exception("Unhandled exception in worker.")
try:
gt.join()
except greenlet.GreenletExit:
pass
except Exception:
self.log.exception("Unhandled exception in worker.")
finally:
gt._conn.close()

Expand Down
37 changes: 20 additions & 17 deletions gunicorn/workers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,30 @@ def run(self):
else:
return
raise
except SystemExit:
return

def handle(self, client, addr):
try:
parser = http.RequestParser(client)
req = parser.next()
self.handle_request(req, client, addr)
except StopIteration:
self.log.debug("Ignored premature client disconnection.")
except socket.error, e:
if e[0] != errno.EPIPE:
try:
parser = http.RequestParser(client)
req = parser.next()
self.handle_request(req, client, addr)
except StopIteration:
self.log.debug("Ignored premature client disconnection.")
except socket.error, e:
if e[0] != errno.EPIPE:
self.log.exception("Error processing request.")
else:
self.log.debug("Ignoring EPIPE")
except Exception, e:
self.log.exception("Error processing request.")
else:
self.log.debug("Ignoring EPIPE")
except Exception, e:
self.log.exception("Error processing request.")
try:
# Last ditch attempt to notify the client of an error.
mesg = "HTTP/1.1 500 Internal Server Error\r\n\r\n"
util.write_nonblock(client, mesg)
except:
pass
try:
# Last ditch attempt to notify the client of an error.
mesg = "HTTP/1.1 500 Internal Server Error\r\n\r\n"
util.write_nonblock(client, mesg)
except:
pass
finally:
util.close(client)

Expand Down
Loading

0 comments on commit cd5756f

Please sign in to comment.