[issue39660] Contextvars: Optional callbacks on state change

2020-02-20 Thread Leonard Lausen
Leonard Lausen added the comment: > 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. I agree the C library could check

[issue39660] Contextvars: Optional callbacks on state change

2020-02-20 Thread Yury Selivanov
Yury Selivanov added the comment: > 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

[issue39660] Contextvars: Optional callbacks on state change

2020-02-20 Thread Yury Selivanov
Yury Selivanov 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

[issue39660] Contextvars: Optional callbacks on state change

2020-02-20 Thread Leonard Lausen
Leonard Lausen added the comment: Consider a `lib = ctypes.CDLL(lib_path, ctypes.RTLD_LOCAL)` which provides APIs `lib.compute`, `lib.set_state` and a Python interface wrapping both in `def compute`, `def set_state`. Let's assume `lib.set_state` sets a thread-local state in the library

[issue39660] Contextvars: Optional callbacks on state change

2020-02-20 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39660] Contextvars: Optional callbacks on state change

2020-02-19 Thread Yury Selivanov
Yury Selivanov added the comment: > Unfortunately, if Python is used as a frontend for a native libray (eg > accessed via ctypes), and in case that the state of interest is managed in > the native library, contextvar API is insufficient. Please elaborate with a clearer example. --

[issue39660] Contextvars: Optional callbacks on state change

2020-02-16 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +yselivanov ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39660] Contextvars: Optional callbacks on state change

2020-02-16 Thread Leonard Lausen
New submission from Leonard Lausen : contextvars provide APIs to manage, store, and access context-local state. Unfortunately, if Python is used as a frontend for a native libray (eg accessed via ctypes), and in case that the state of interest is managed in the native library, contextvar API