pyramid threadlocal在响应的应用程序中不起作用

2024-06-16 12:32:04 发布

您现在位置:Python中文网/ 问答频道 /正文

具有以下示例代码:

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()
    config.add_view(hello_world)
    app = config.make_wsgi_app()
    serve(app, host='0.0.0.0')

我收到当前请求:无。那么,threadlocalapp_iter内部不起作用?我有实际的代码,需要访问远离视图的threadlocal几层,传递request变量会很麻烦。在


Tags: 代码fromtestimportpyramidconfigapphello
2条回答

可能是错了?在

return Response(app_iter=test_iter())

或者

^{pr2}$

根据Pyramid docs的说法,线程本地堆栈应该在使用app_iter之后才会弹出(参见步骤16和18),尽管我在运行示例时看到了与您相同的行为。由于文档和行为冲突其中一个是错误的,我建议与金字塔的人filing a bug。在

相关问题 更多 >