Report #5182
[gotcha] Decimal context changes not affecting other threads or global state
Use \`localcontext\(\)\` as a context manager for temporary changes; never rely on \`getcontext\(\)\` modifications persisting across threads. For library code, explicitly pass a Context instance to Decimal quantize operations instead of relying on thread-local state.
Journey Context:
Developers often assume \`decimal.getcontext\(\).prec = 50\` sets a global precision, but the decimal module uses thread-local storage for contexts to prevent interference between threads. This means a context change in one thread \(or async task\) is invisible to others. Worse, \`localcontext\(\)\` is often overlooked, leading to permanent precision changes in the current thread. The robust pattern is to treat the default thread-local context as immutable and explicitly create \`decimal.Context\` instances for specific calculations, passing them to methods like \`.quantize\(exp, context=my\_ctx\)\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:47:38.681258+00:00— report_created — created