~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to swift/common/wsgi.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-28 09:40:30 UTC
  • mfrom: (1.2.16)
  • Revision ID: package-import@ubuntu.com-20130128094030-aetz57x2qz9ye2d4
Tags: 1.7.6-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from StringIO import StringIO
25
25
 
26
26
import eventlet
 
27
import eventlet.debug
27
28
from eventlet import greenio, GreenPool, sleep, wsgi, listen
28
29
from paste.deploy import loadapp, appconfig
29
30
from eventlet.green import socket, ssl
32
33
from swift.common.swob import Request
33
34
from swift.common.utils import capture_stdio, disable_fallocate, \
34
35
    drop_privileges, get_logger, NullLogger, config_true_value, \
35
 
    validate_configuration
 
36
    validate_configuration, get_hub
36
37
 
37
38
 
38
39
def monkey_patch_mimetools():
70
71
        bind_addr[0], bind_addr[1], socket.AF_UNSPEC, socket.SOCK_STREAM)
71
72
        if addr[0] in (socket.AF_INET, socket.AF_INET6)][0]
72
73
    sock = None
73
 
    retry_until = time.time() + 30
 
74
    bind_timeout = int(conf.get('bind_timeout', 30))
 
75
    retry_until = time.time() + bind_timeout
74
76
    warn_ssl = False
75
77
    while not sock and time.time() < retry_until:
76
78
        try:
85
87
                raise
86
88
            sleep(0.1)
87
89
    if not sock:
88
 
        raise Exception('Could not bind to %s:%s after trying for 30 seconds' %
89
 
                        bind_addr)
 
90
        raise Exception(_('Could not bind to %s:%s '
 
91
                          'after trying for %s seconds') % (
 
92
                              bind_addr[0], bind_addr[1], bind_timeout))
90
93
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
91
94
    # in my experience, sockets can hang around forever without keepalive
92
95
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
132
135
        wsgi.HttpProtocol.log_message = \
133
136
            lambda s, f, *a: logger.error('ERROR WSGI: ' + f % a)
134
137
        wsgi.WRITE_TIMEOUT = int(conf.get('client_timeout') or 60)
135
 
        eventlet.hubs.use_hub('poll')
 
138
 
 
139
        eventlet.hubs.use_hub(get_hub())
136
140
        eventlet.patcher.monkey_patch(all=False, socket=True)
 
141
        eventlet_debug = config_true_value(conf.get('eventlet_debug', 'no'))
 
142
        eventlet.debug.hub_exceptions(eventlet_debug)
137
143
        app = loadapp('config:%s' % conf_file,
138
144
                      global_conf={'log_name': log_name})
139
145
        pool = GreenPool(size=1024)
207
213
 
208
214
    :param conf_file: Path to paste.deploy style configuration file
209
215
    :param app_section: App name from conf file to load config from
210
 
    :returns the loaded application entry point
 
216
    :returns: the loaded application entry point
211
217
    :raises ConfigFileError: Exception is raised for config file error
212
218
    """
213
219
    try:
244
250
    """
245
251
    def __init__(self, wsgi_app):
246
252
        self.app = wsgi_app
247
 
        # Results from the last call to self._start_response.
248
 
        self._response_status = None
249
 
        self._response_headers = None
250
 
        self._response_exc_info = None
251
253
 
252
254
    def _start_response(self, status, headers, exc_info=None):
253
255
        """
262
264
        """
263
265
        Ensures start_response has been called before returning.
264
266
        """
265
 
        resp = iter(self.app(env, self._start_response))
 
267
        self._response_status = None
 
268
        self._response_headers = None
 
269
        self._response_exc_info = None
 
270
        resp = self.app(env, self._start_response)
 
271
        # if start_response has been called, just return the iter
 
272
        if self._response_status is not None:
 
273
            return resp
 
274
        resp = iter(resp)
266
275
        try:
267
276
            first_chunk = resp.next()
268
277
        except StopIteration: