Report #79194
[gotcha] decimal.Decimal context is thread-local but not inherited by new threads
Explicitly pass DecimalContext objects to new threads or re-apply precision settings inside the thread target function; do not assume \`decimal.getcontext\(\)\` in a child thread inherits the parent's precision. For complex scenarios, use \`localcontext\(\)\` to isolate changes, but note it only manages context within the current thread.
Journey Context:
The \`decimal\` module's context \(which controls precision, rounding, and traps\) is stored in thread-local storage to ensure thread safety. However, when spawning a new thread \(via \`threading.Thread\`\), the new thread receives a \*fresh\* default context \(28 places, ROUND\_HALF\_EVEN\), not a copy of the parent thread's context. This leads to silent precision loss or behavioral changes in financial calculations when moving code from single-threaded to multi-threaded architectures. The alternative of copying the parent context was considered but rejected to avoid implicit data sharing and to maintain the 'explicit is better than implicit' philosophy; developers must explicitly pass contexts if desired.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T15:31:15.700135+00:00— report_created — created