>
> From: "Roberto De Ioris" <[email protected]>
>
> One of my customer is doing this to force django loading on startup:
>
> from django.core.handlers.wsgi import WSGIHandler
>
> application = WSGIHandler()
>
> # generate a fake request
> application({'REQUEST_METHOD':'GET', 'PATH_INFO':'/',
> 'SERVER_NAME':'foobar'}, uwsgi.start_response)
>
>
> I do not remember if some other variable is needed, you can eventually add
> them in the dictionary if you receive an error.
>
>
I tried this in my setup, but the worker segfaults without informative
logging, when Django's WSGIHandler calls the uwsgi.start_response function.

I added print statements around that call:

        print "Django WSGIHandler calling start_response with status %s and
headers:\n%s" % (status, pformat(response_headers))
        start_response(status, response_headers)
        print "Django WSGIHandler ...called start_response"

and in the uwsgi log I get:

Django WSGIHandler calling start_response with status 200 OK and headers:
[('X-DataMarket-API-Hits', '0'),
 ('Vary', 'Cookie'),
 ('X-DataMarket-UserID', '5'),
 ('Content-Type', 'application/javascript; charset=utf-8'),
 ('Content-Language', 'en')]
removed uwsgi instance test.ini

(and the "called start_response" line never comes)

and in /var/log/messages I get one of these for each worker crash:

uwsgi[29048]: segfault at 0 ip 08084b4b sp bff974f0 error 6 in
uwsgi[8048000+57000]

(pid and sp differs, of course, but the other stuff is constant)

I copied the whole environ dictionary sent by uwsgi in a normal wsgi
invocation, replacing wsgi.input and wsgi.errors with cStringIO.StringIO
instances, so I don't think there is anything wrong with my application
invocation. Still posting it below.

I was running latest stable, 0.9.9.2, as emperor with two vassals, when I
tried this out and saw it fail. Tried going to 1.0-rc6, and simplified to
one vassal to make logs clearer; same problem.

It seems to me like uwsgi is not ready to receive the start_response call
right at the time of loading the wsgi application (and it does not express
its unreadiness very politely :) ).

Regards,

- Gulli




import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

try:
    import uwsgi
except:
    pass
else:
    try:
        import cStringIO
        input = cStringIO.StringIO()
        errors = cStringIO.StringIO()
        print 'TESTING: calling application'
        application(
{
  'CONTENT_LENGTH': '',
  'CONTENT_TYPE': '',
  'DOCUMENT_ROOT': '/usr/local/nginx/html',
  'HTTP_ACCEPT':
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
  'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch',
  'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8',
  'HTTP_CONNECTION': 'keep-alive',
  'HTTP_HOST': 'test.datamarket.com',
  'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2)
AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.41 Safari/535.7',
  'PATH_INFO': '/api/v1/info.json',
  'QUERY_STRING': 'ds=c',
  'REMOTE_ADDR': '167.177.112.172',
  'REMOTE_PORT': '65420',
  'REQUEST_METHOD': 'GET',
  'REQUEST_URI': '/__ping__',
  'SERVER_NAME': 'mytest.com',
  'SERVER_PORT': '80',
  'SERVER_PROTOCOL': 'HTTP/1.1',
  'uwsgi.node': 'itchy',
  'uwsgi.version': '1.0-dev',
  'wsgi.multiprocess': True,
  'wsgi.multithread': False,
  'wsgi.run_once': False,
  'wsgi.url_scheme': 'http',
  'wsgi.version': (1, 0),
  'wsgi.input': input,
  'wsgi.errors': errors,
},
            uwsgi.start_response)
    except:
        print 'TESTING: got exception'
        import traceback
        traceback.print_exc()
    else:
        print 'TESTING: survived application call'
    finally:
        print 'TESTING: reached finally clause'
        import traceback
        traceback.print_exc()
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to