Flask如何保持请求全局线程安全 [英] How does Flask keep the request global threadsafe

查看:58
本文介绍了Flask如何保持请求全局线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在烧瓶中,每个功能都可以访问 request 全局变量.flask的设计者如何在另一个请求开始时阻止全局在一个请求中间被覆盖?

In flask every function has access to a request global. How do the designers of flask stop that global from being overwritten in the middle of one request when another one starts?

推荐答案

这是线程局部的,而不是真正的全局的.由于每个线程一次只能处理一个请求,因此没有干扰的危险.

It's a threadlocal, not a true global. Since each thread can only be dealing with one request at a time, there's no danger of interference.

事实上,Flask文档中有对此的完整描述此处.

In fact there's a full description of exactly this in the Flask docs here.

(当然,并不一定使其成为一个好的设计.)

(Still doesn't necessarily make it a good design, of course.)

这篇关于Flask如何保持请求全局线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆