diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py index 0acb733a..6062117e 100644 --- a/gunicorn/app/base.py +++ b/gunicorn/app/base.py @@ -74,7 +74,7 @@ class Application(object): } try: execfile(opts.config, cfg, cfg) - except Exception, e: + except Exception: print "Failed to read config file: %s" % opts.config traceback.print_exc() sys.exit(1) diff --git a/gunicorn/app/djangoapp.py b/gunicorn/app/djangoapp.py index c4604492..baed61cd 100644 --- a/gunicorn/app/djangoapp.py +++ b/gunicorn/app/djangoapp.py @@ -3,7 +3,6 @@ # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. -import logging import os import sys import traceback @@ -60,7 +59,7 @@ class DjangoApplication(Application): for part in parts[1:]: settings_mod = getattr(settings_mod, part) setup_environ(settings_mod) - except ImportError, e: + except ImportError: return self.no_settings(self.settings_modname, import_error=True) def no_settings(self, path, import_error=False): @@ -102,7 +101,7 @@ class DjangoApplicationCommand(Application): } try: execfile(self.config_file, cfg, cfg) - except Exception, e: + except Exception: print "Failed to read config file: %s" % self.config_file traceback.print_exc() sys.exit(1) diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 95ae4104..5aa8a4c0 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -14,7 +14,7 @@ import sys import time import traceback -from gunicorn.errors import ConfigError, HaltServer +from gunicorn.errors import HaltServer from gunicorn.pidfile import Pidfile from gunicorn.sock import create_socket from gunicorn import util diff --git a/gunicorn/config.py b/gunicorn/config.py index f6e45f56..029556fe 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -9,7 +9,6 @@ import inspect import optparse import os import pwd -import sys import textwrap import types diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index 594c72bd..811ced6a 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -7,7 +7,6 @@ from __future__ import with_statement import errno import socket -import traceback import gunicorn.http as http import gunicorn.http.wsgi as wsgi @@ -54,7 +53,6 @@ class AsyncWorker(base.Worker): def handle_request(self, req, sock, addr): try: - debug = self.cfg.debug or False self.cfg.pre_request(self, req) resp, environ = wsgi.create(req, sock, addr, self.address, self.cfg) self.nr += 1 diff --git a/gunicorn/workers/base.py b/gunicorn/workers/base.py index 04d77eae..b65ea1dd 100644 --- a/gunicorn/workers/base.py +++ b/gunicorn/workers/base.py @@ -9,7 +9,6 @@ import os import random import signal import sys -import tempfile import traceback @@ -116,9 +115,7 @@ class Worker(object): self.alive = False sys.exit(0) - def handle_error(self, client, exc): - if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,)): @@ -144,8 +141,10 @@ class Worker(object): util.write_error(client, mesg, status_int=status_int, reason=reason) except: - self.log.warning("Unexpected error" % traceback.format_exc()) - pass + if self.debug: + self.log.warning("Unexpected error %s" % traceback.format_exc()) + else: + self.log.warning("Unexpected error %s" % str(exc)) def handle_winch(self, sig, fname): # Ignore SIGWINCH in worker. Fixes a crash on OpenBSD. diff --git a/gunicorn/workers/ggevent.py b/gunicorn/workers/ggevent.py index 288a311b..f39ff460 100644 --- a/gunicorn/workers/ggevent.py +++ b/gunicorn/workers/ggevent.py @@ -123,6 +123,7 @@ class GeventBaseWorker(Worker): @classmethod def setup(cls): from gevent import monkey + monkey.noisy = False monkey.patch_all() @@ -152,6 +153,14 @@ class GeventBaseWorker(Worker): server.stop(timeout=self.timeout) except: pass + + def init_process(self): + #gevent doesn't reinitialize dns for us after forking + #here's the workaround + gevent.core.dns_shutdown(fail_requests=1) + gevent.core.dns_init() + super(GeventBaseWorker, self).init_process() + class WSGIHandler(wsgi.WSGIHandler): diff --git a/gunicorn/workers/sync.py b/gunicorn/workers/sync.py index b92e7765..cb283dbc 100644 --- a/gunicorn/workers/sync.py +++ b/gunicorn/workers/sync.py @@ -83,7 +83,6 @@ class SyncWorker(base.Worker): def handle_request(self, req, client, addr): try: - debug = self.cfg.debug or False self.cfg.pre_request(self, req) resp, environ = wsgi.create(req, client, addr, self.address, self.cfg)