0Pricing
Flask Academy · Lesson

Context Locals and Thread Safety

How proxies stay correct across requests.

The Magic Question

How does one global request object stay correct when many visitors hit your app at once? The answer is context locals.

They Look Global

Objects like request and g look like plain globals you import once. But they are special proxies, not ordinary shared variables.

from flask import request

All lessons in this course

  1. App Context vs Request Context
  2. current_app and the g Object
  3. Context Locals and Thread Safety
  4. Push a Context in Scripts and Shells
← Back to Flask Academy