remove some useless code. pyflakes my friend.

This commit is contained in:
benoitc 2010-12-22 19:52:34 +01:00
parent c90ecd1eba
commit 16fd5d3c20
8 changed files with 17 additions and 14 deletions

View File

@ -74,7 +74,7 @@ class Application(object):
} }
try: try:
execfile(opts.config, cfg, cfg) execfile(opts.config, cfg, cfg)
except Exception, e: except Exception:
print "Failed to read config file: %s" % opts.config print "Failed to read config file: %s" % opts.config
traceback.print_exc() traceback.print_exc()
sys.exit(1) sys.exit(1)

View File

@ -3,7 +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.
import logging
import os import os
import sys import sys
import traceback import traceback
@ -60,7 +59,7 @@ class DjangoApplication(Application):
for part in parts[1:]: for part in parts[1:]:
settings_mod = getattr(settings_mod, part) settings_mod = getattr(settings_mod, part)
setup_environ(settings_mod) setup_environ(settings_mod)
except ImportError, e: except ImportError:
return self.no_settings(self.settings_modname, import_error=True) return self.no_settings(self.settings_modname, import_error=True)
def no_settings(self, path, import_error=False): def no_settings(self, path, import_error=False):
@ -102,7 +101,7 @@ class DjangoApplicationCommand(Application):
} }
try: try:
execfile(self.config_file, cfg, cfg) execfile(self.config_file, cfg, cfg)
except Exception, e: except Exception:
print "Failed to read config file: %s" % self.config_file print "Failed to read config file: %s" % self.config_file
traceback.print_exc() traceback.print_exc()
sys.exit(1) sys.exit(1)

View File

@ -14,7 +14,7 @@ import sys
import time import time
import traceback import traceback
from gunicorn.errors import ConfigError, HaltServer from gunicorn.errors import HaltServer
from gunicorn.pidfile import Pidfile from gunicorn.pidfile import Pidfile
from gunicorn.sock import create_socket from gunicorn.sock import create_socket
from gunicorn import util from gunicorn import util

View File

@ -9,7 +9,6 @@ import inspect
import optparse import optparse
import os import os
import pwd import pwd
import sys
import textwrap import textwrap
import types import types

View File

@ -7,7 +7,6 @@ from __future__ import with_statement
import errno import errno
import socket import socket
import traceback
import gunicorn.http as http import gunicorn.http as http
import gunicorn.http.wsgi as wsgi import gunicorn.http.wsgi as wsgi
@ -54,7 +53,6 @@ class AsyncWorker(base.Worker):
def handle_request(self, req, sock, addr): def handle_request(self, req, sock, addr):
try: try:
debug = self.cfg.debug or False
self.cfg.pre_request(self, req) self.cfg.pre_request(self, req)
resp, environ = wsgi.create(req, sock, addr, self.address, self.cfg) resp, environ = wsgi.create(req, sock, addr, self.address, self.cfg)
self.nr += 1 self.nr += 1

View File

@ -9,7 +9,6 @@ import os
import random import random
import signal import signal
import sys import sys
import tempfile
import traceback import traceback
@ -116,9 +115,7 @@ class Worker(object):
self.alive = False self.alive = False
sys.exit(0) sys.exit(0)
def handle_error(self, client, exc): def handle_error(self, client, exc):
if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod, if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod,
InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,)): InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,)):
@ -144,8 +141,10 @@ class Worker(object):
util.write_error(client, mesg, status_int=status_int, util.write_error(client, mesg, status_int=status_int,
reason=reason) reason=reason)
except: except:
self.log.warning("Unexpected error" % traceback.format_exc()) if self.debug:
pass self.log.warning("Unexpected error %s" % traceback.format_exc())
else:
self.log.warning("Unexpected error %s" % str(exc))
def handle_winch(self, sig, fname): def handle_winch(self, sig, fname):
# Ignore SIGWINCH in worker. Fixes a crash on OpenBSD. # Ignore SIGWINCH in worker. Fixes a crash on OpenBSD.

View File

@ -123,6 +123,7 @@ class GeventBaseWorker(Worker):
@classmethod @classmethod
def setup(cls): def setup(cls):
from gevent import monkey from gevent import monkey
monkey.noisy = False
monkey.patch_all() monkey.patch_all()
@ -152,6 +153,14 @@ class GeventBaseWorker(Worker):
server.stop(timeout=self.timeout) server.stop(timeout=self.timeout)
except: except:
pass 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): class WSGIHandler(wsgi.WSGIHandler):

View File

@ -83,7 +83,6 @@ class SyncWorker(base.Worker):
def handle_request(self, req, client, addr): def handle_request(self, req, client, addr):
try: try:
debug = self.cfg.debug or False
self.cfg.pre_request(self, req) self.cfg.pre_request(self, req)
resp, environ = wsgi.create(req, client, addr, resp, environ = wsgi.create(req, client, addr,
self.address, self.cfg) self.address, self.cfg)