问题
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?
回答1:
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.
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.)
来源:https://stackoverflow.com/questions/23726788/how-does-flask-keep-the-request-global-threadsafe