Enabling thread_inherit_context and context_aware_warnings by default on both builds

Thank you all for finding real-world examples where turning on the warning will cause pain. I now think we shouldn’t warn about this in 3.15 and am no longer advocating for that.

In addition to django/asgiref, this will also cause warnings in sentry-sdk and OpenTelemetry.

So I think Neil’s thread_inheritable idea needs to become a three-way option with the following behaviors:

  • True: Newly spawned threads capture the context.
  • None: Threads start with no inherited context. A future Python version may warn about the thread_inherit_context startup option changing default values in the future.
  • False: Threads start with no inherited context. A future Python version will never warn about this.

NumPy can then use thread_inheritable=True and other libraries like asgiref, django, sentry-sdk, and OpenTelemetry can have the entire 3.16 release cycle to make sure their ContextVars are created with thread_inheritable=False.

1 Like