【问题标题】:Creating a Pylons Thread with Access to app_globals创建一个可以访问 app_globals 的 Pylons 线程
【发布时间】:2011-01-19 21:38:55
【问题描述】:

我想创建一个在我的 pylons 环境的后台运行的进程,不受客户端请求的约束,可以访问 pylons app_globals 对象。该过程的一般目的是检查客户端会话是否过期并执行一些过期后分析。

这可能吗?我尝试在config/environment.py 文件中创建一个线程,但是当我尝试访问app_globals 的属性时,我收到以下错误:

TypeError: No object (name: app_globals) has been registered for this thread

提前致谢,

【问题讨论】:

    标签: python multithreading pylons wsgi


    【解决方案1】:

    您需要注册 app_globals(在每个请求注册的 pylons app_globals 中):

    pylons.app_globals._push_object(config['pylons.app_globals'])
    

    【讨论】:

    • 这对我有用,仅供参考。接受的答案没有。谢谢。
    【解决方案2】:

    您尝试访问的对象是 StackedObjectProxy 由 pylons 为每个请求注册的服务线程。

    如果你只是想看的话,用config里面的那个是安全的:

    config.get('pylons.app_globals') or config.get('pylons.g')
    

    【讨论】:

    • 这对我有用(pylons 0.9.7),但pylons.app_globals._push_object(config['pylons.app_globals']) 没有。可能是我用错了。
    • 我对新版本 Pylons 的解决方案。
    猜你喜欢
    • 2014-02-12
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    相关资源
    最近更新 更多