threadlocal doesn't work inside Response's app_iter #211

sayap opened this Issue Jun 8, 2011 · 1 comment


None yet

2 participants

sayap commented Jun 8, 2011

With the following sample code:

from webob import Response
from paste.httpserver import serve

def test_iter():
    from pyramid import threadlocal
    yield 'current request: %s' % threadlocal.get_current_request()

def hello_world(request):
    return Response(app_iter=test_iter())

if __name__ == '__main__':
    from pyramid.config import Configurator
    config = Configurator()
    app = config.make_wsgi_app()
    serve(app, host='')

I get current request: None. So, threadlocal doesn't work inside app_iter? This behavior seems to contradict the documentation:

mcdonc commented Jun 8, 2011

An app_iter that is a generator isn't invoked until after the threadlocal stack is popped, because the app_iter isn't iterated over until the server (or middleware that unwinds it) gets a hold of it. You'll have to obtain it outside of the app_iter and pass it in somehow.

@mcdonc mcdonc closed this Jun 8, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment