I am reading the Flask documentation (specifically, the Foreword for Experienced Programmers chapter) and I read this -
One of the design decisions in Flask was that simple tasks should be simple; they should not take a lot of code and yet they should not limit you. Because of that, Flask has few design choices that some people might find surprising or unorthodox. For example, Flask uses thread-local objects internally so that you don’t have to pass objects around from function to function within a request in order to stay threadsafe. This approach is convenient, but requires a valid request context for dependency injection or when attempting to reuse code which uses a value pegged to the request. The Flask project is honest about thread-locals, does not hide them, and calls out in the code and documentation where they are used.
What does this mean? Specifically the following questions -
- What are thread local objects? How and when they are used and what purpose do they solve?
- How using thread-local objects internally ensure thread safety and how does passing objects to function result in not-thread-safe?
- What is the meaning of a valid request context in this case?