Context Management
1 Storage Management
Flask support Coroutines by dict and greenlet.getcurrent
, it allocates space for each greenlet and store them in a dictionary
- create a dictionary called
__storage__
- set, get from
__storage__
usinggreenlet.getcurrent
as key
1 | try: |
2 Request Context
- Request context includes request and session
- Basically, each request comes
- Capsulate
environ
into aRequestContext
object - Add it into
__storage__
dictionary - Dispatch request to each view file and do operation
- Remove it from
__storage__
dictionary
- Capsulate
Picture for step 1, 2, 4
Picture for step 3 example
partial()
: it is quite funcional programmingobject.__setattr__(self, '_LocalProxy__local', local)
: stuck here for quite a while. python3 documentation
3 App Context
- It is quite similar as Request Context
- It includes
current_app
andg