酸洗Django请求对象 [英] Pickling Django request objects
问题描述
我正在尝试拣选一个请求对象,以便我可以在一个带有有效输入的调试器中运行我的视图代码。但是,我正在获得
I'm trying to pickle a request object so that I can run my view code in a debugger with valid input. However, I'm getting
Can't pickle 'lock' object: <thread.lock object at 0x93ad240>
我查看了请求对象,但是找不到一个thread.lock对象。有谁知道它在哪里?有没有更好的方法来解决这个问题?
I looked through the request object, but couldn't find a thread.lock object anywhere in it. Does anyone know where it is? Is there a better way to go about this?
推荐答案
一般来说,您无法为任何Web服务器挑选HTTP请求对象。酸洗过程不会对对象本身腌渍,而是其所有引用。
Generally, you cannot pickle HTTP requests objects for any web server. Pickling process does not pickle on the object itself, but all its references.
通常的Web服务器设计模式是让每个HTTP请求都运行自己的线程。线程和HTTP请求之间必须有连接。因此,HTTP对象与Web服务器的生命周期相关联,不能从Web服务器上下文中取出。
The usual web server design pattern is to have each HTTP request running its own thread. There must be a connection between the thread and HTTP request. Thus, the HTTP object is tied to the life cycle of web server and cannot be taken out of the web server context.
您可能想要做的是腌制HTTP请求对象的内容,并使用此内容作为有效负载重新创建请求。
What you probably want to do is to pickle the contents of HTTP request object and re-create requests using this content as a payload.
这篇关于酸洗Django请求对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!