Why does Pylons use StackedObjectProxies instead of threading.local?

人走茶凉 提交于 2019-12-22 14:00:16

问题


It seems like threading.local is more straightforward and more robust.


回答1:


StackedObjectProxy uses a threading.local underneath it. Pylons doesn't use plain threading.locals for 2 reasons:

1) it'd be a more intrusive API than a proxy. E.g. request().POST.get('file') vs request.POST.get('file')

2) StackedObjectProxys are not only thread safe, but also "request safe" -- meaning it's safe for a Pylons application to be embedded in another and reference the same proxy objects. The need for this kind of safety is rare, but is certainly a possibility with how easy it is for WSGI apps to call other WSGI apps + the use of global objects

See the paste.registry docs for more information




回答2:


Because threading.local is new in Python 2.4. The StackedObjectProxy uses threading.local if it can.



来源:https://stackoverflow.com/questions/1686768/why-does-pylons-use-stackedobjectproxies-instead-of-threading-local

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!