概述
from django.utils.thread_support import currentThread _requests = {} def get_request(): return _requests[currentThread()] class GlobalRequestMiddleware(object): def process_request(self,request): _requests[currentThread()] = request
当然,它引发了一个例外:
ImproperlyConfigured: Error importing middleware myProject.middleware.global: "No module named thread_support"
编辑:
from threading import local _active = local() def get_request(): return _active.request class GlobalRequestMiddleware(object): def process_view(self,request,view_func,view_args,view_kwargs): _active.request = request return None
现在我有一个问题:是否会导致内存泄漏? _active会发生什么?当请求死亡时它被清理了吗?无论如何,已经发布了一个有效的答案.我将接受它,但任何其他(更好的,如果可能的话)解决方案将非常受欢迎!谢谢!
from django.utils.thread_support import currentThread currentThread()
同
from threading import current_thread current_thread()
总结
以上是编程之家为你收集整理的python – django 1.5中的django.utils.thread_support全部内容,希望文章能够帮你解决python – django 1.5中的django.utils.thread_support所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧