This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author yselivanov
Recipients leezu, rhettinger, yselivanov
Date 2020-02-20.23:51:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582242667.43.0.000461209476582.issue39660@roundup.psfhosted.org>
In-reply-to
Content
> Would there be too much overhead if allowing specification of a python function that contextvars calls on context changes?

Potentially yes, especially if we allow more than one context change callback.  Allowing just one makes the API inflexible (what if you want to use two libraries from PyPI that both want to use the callback).  Allowing multiple context change callbacks leads to complicated API.

For extra context: context switches occur on every callback invocation in asyncio and there can be thousands of them per seconds (or even more). Adding any extra code to context switching code will noticeably degrade the performance.

In general, I'd suggest patching the C library to make state management customizable (like CPython allows you to customize which memory allocator to use)
History
Date User Action Args
2020-02-20 23:51:07yselivanovsetrecipients: + yselivanov, rhettinger, leezu
2020-02-20 23:51:07yselivanovsetmessageid: <1582242667.43.0.000461209476582.issue39660@roundup.psfhosted.org>
2020-02-20 23:51:07yselivanovlinkissue39660 messages
2020-02-20 23:51:07yselivanovcreate