[issue39660] Contextvars: Optional callbacks on state change

Yury Selivanov report at bugs.python.org
Thu Feb 20 17:44:54 EST 2020


Yury Selivanov <yselivanov at gmail.com> added the comment:

> Is there any existing API that can be used to call `lib.set_state` on context changes?

No, but there's C API that you can use to get/set contextvars. If a C library is hard coded to use threadlocals I'm afraid there's nothing we can do about it except fixing their C code to make state storage pluggable.

What library do you have in mind?

> If not, would it make sense to extend `contexvars` to allow users to configure that `lib.set_state` is called on context change?

Theoretically yes, for debug purposes at least.  But I still fail to see how you could use that API even if it existed.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39660>
_______________________________________


More information about the Python-bugs-list mailing list