You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add --without-decimal-contextvar option to use just threads in decimal #83975
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/skrah'closed_at=Nonecreated_at=<Date2020-02-29.11:24:13.696>labels= ['extension-modules', '3.8', 'type-bug', '3.7', '3.9']
title='Add --without-decimal-contextvar option to use just threads in decimal'updated_at=<Date2020-03-03.15:31:20.696>user='https://github.com/skrah'
Activity
skrah commentedon Feb 29, 2020
bpo-39776 has shown that it is hard to understand the interaction between
ContextVars and threading in embedded scenarios.
I want to understand the code again, so I'm adding back a compile time
option to enable the thread local context that was present prior to
f13f12d.
skrah commentedon Feb 29, 2020
Also, when I'm debugging things like bpo-39776, I don't want to
switch between Python versions.
skrah commentedon Feb 29, 2020
New changeset 815280e by Stefan Krah in branch 'master':
bpo-39794: Add --without-decimal-contextvar (bpo-18702)
815280e
skrah commentedon Feb 29, 2020
New changeset 4d70124 by Stefan Krah in branch '3.8':
[3.8] bpo-39794: Add --without-decimal-contextvar (GH-18702)
4d70124
skrah commentedon Feb 29, 2020
New changeset c4ca1f8 by Stefan Krah in branch '3.7':
[3.7] bpo-39794: Add --without-decimal-contextvar (GH-18702)
c4ca1f8
gpshead commentedon Mar 1, 2020
While i don't think this was needed in 3.7 and 3.8, you kept the default behavior the same so I don't think it is a problem.
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?
rhettinger commentedon Mar 2, 2020
+1 for the backport. A build option isn't new feature, but it does provide a debugging tool and work-around for people who are having problems.
skrah commentedon Mar 2, 2020
For the people who find this issue via a search engine:
The defaults in 3.7, 3.8 and 3.9 are unchanged (you get
the ContextVar).
./configure --without-decimal-contextvar enables the exact
TLS context code from 3.3-3.6. There is no new code.
On Windows you need to edit PC\pyconfig.h to enable the TLS
context.
There are extensive tests for the flag in:
Modules/_decimal/tests/runall-memorydebugger.sh
skrah commentedon Mar 2, 2020
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:
skrah commentedon Mar 2, 2020
To make things more clear (it is good that Gregory asked):
ONLY use this flag if you don't use coroutines at all
OR control ALL async libraries in your application.
Random async libraries from PyPI may rely on the
ContextVar and silently give incorrect results.
skrah commentedon Mar 3, 2020
bpo-39776 is fixed, but _pydecimal was also affected, see msg363266.
serhiy-storchaka commentedon Jul 3, 2026
The work was completed and backported in 2020, and the option was later removed in 3.13. Closing as completed.