问题描述
如果我在瓶子里有全局变量并且有多个用户同时访问这个站点,一个人会话能否覆盖另一个人员会话的全局变量,或者每次请求时瓶子是否会创建我的站点和程序代码的唯一实例从一个用户浏览器?一般来说,全局变量是请求之间共享。
某些WSGI服务器可以为每个请求使用一个新的单独进程,但这不是一种有效的扩展请求的方法。大多数将使用treading或几个子进程来传播负载,但即使在分开的子进程的情况下,每个子进程将在其生命周期中处理多个请求。
其他单词:否,Flask将不会保护您的全局变量不被不同用户共享。
If I have global variables in flask and have multiple users accessing the site at once, can one persons session overwrite the global variables of another persons session, or does flask make a unique instance of my site and program code each time its requested from a users browser?
Generally speaking, global variables are shared between requests.
Some WSGI servers can use a new separate process for each request, but that is not an efficient way to scale your requests. Most will use treading or several child processes to spread the load but even in the case of separate child processes each subprocess will have to handle multiple requests during its lifetime.
In other words: no, Flask will not protect your global variables from being shared between different users.
这篇关于Flask全局变量和会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!