[issue39794] Add --without-decimal-contextvar option to use just threads in decimal

Stefan Krah report at bugs.python.org
Mon Mar 2 06:01:22 EST 2020


Stefan Krah <stefan at bytereef.org> added the comment:

> If someone builds an interpreter with this configure flag, does it break
> compatibility with anything that code may have started to expect as of 3.7?

Yes, anything that relies on the implicit context being coroutine-safe
does not work.  The only test that expectedly breaks in the stdlib is:

   Lib/test/test_asyncio/test_context.py


Basically you can't use operators inside coroutines in the same thread
if both coroutines use a different implicit context.

You can of course replace all operators inside coroutines by the
corresponding context methods:

   # Unsafe with TLS context:
   async def foo():
       with localcontext(Context(prec=10)):
           x = Decimal(1) / 9

   # Safe, just avoid the TLS context:
   async def foo():
       c = Context(prec=10)
       x = c.divide(Decimal(1), 9)

----------

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


More information about the Python-bugs-list mailing list