Report #17639
[gotcha] Decimal precision or rounding inconsistent between threads after context modification
Never modify the global decimal context \(\`getcontext\(\).prec = x\`\) in threaded applications; always use \`localcontext\(\)\` for temporary changes. Treat getcontext\(\) as read-only outside of single-threaded initialization.
Journey Context:
decimal.getcontext\(\) returns a thread-local context copied from a master template at thread creation. Modifying it in one thread is safe \(isolated\), but developers often expect changes to propagate to all threads \(global state\) or assume child threads inherit future changes to the master. Additionally, localcontext\(\) is the only safe way to temporarily alter precision for a calculation block; direct mutation of getcontext\(\).prec leaks state if an exception occurs before restoration, and is not thread-safe if done at module level during thread startup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:53:52.395572+00:00— report_created — created