New PEP 550: Execution Context

Yury Selivanov wrote:
This is a new PEP to implement Execution Contexts in Python.
The idea is of course great! A couple of issues for decimal:
Moreover, passing the context explicitly does not work at all for libraries like ``decimal`` or ``numpy``, which use operator overloading.
Instead of "with localcontext() ...", each coroutine can create a new Context() and use its methods, without any loss of functionality. All one loses is the inline operator syntax sugar. I'm aware you know all this, but the entire decimal paragraph sounds a bit as if this option did not exist.
Fast C API for packages like ``decimal`` and ``numpy``.
_decimal relies on caching the most recently used thread-local context, which gives a speedup of about 25% for inline operators: https://github.com/python/cpython/blob/master/Modules/_decimal/_decimal.c#L1... Can this speed be achieved with the execution contexts? IOW, can the lookup of an excecution context be as fast as PyThreadState_GET()? Stefan Krah

This is a new PEP to implement Execution Contexts in Python.
The idea is of course great!
Thanks!
The problem is that almost everybody does use the Decimal type directly, as overloaded operators make it so convenient. It's not apparent that using the decimal this way has a dangerous flaw.
I've seen that, it's a clever trick! With the current PEP 550 semantics it's possible to replicate this trick, you just store a reference to the latest EC in your decimal context for cache invalidation. Because ECs are immutable, it's a safe thing to do. Yury

This is a new PEP to implement Execution Contexts in Python.
The idea is of course great!
Thanks!
The problem is that almost everybody does use the Decimal type directly, as overloaded operators make it so convenient. It's not apparent that using the decimal this way has a dangerous flaw.
I've seen that, it's a clever trick! With the current PEP 550 semantics it's possible to replicate this trick, you just store a reference to the latest EC in your decimal context for cache invalidation. Because ECs are immutable, it's a safe thing to do. Yury
participants (2)
-
Stefan Krah
-
Yury Selivanov