Report #17974
[gotcha] decimal precision changes ignored or lost in multi-threaded applications
Set the decimal context inside each thread using \`decimal.localcontext\(\)\` or explicitly call \`decimal.getcontext\(\)\` and modify it within the thread's execution scope; never assume that setting precision in the main thread affects worker threads.
Journey Context:
The decimal module's context \(precision, rounding mode\) is thread-local via \`getcontext\(\)\`. Developers often set \`decimal.getcontext\(\).prec = 28\` in main thread initialization, expecting it to propagate to ThreadPoolExecutor workers or other threads. It doesn't. Each thread starts with a fresh default context \(28 digits\). In financial applications, this leads to silent precision loss or rounding differences between single-threaded tests and production multi-threaded workloads. The correct pattern is to use \`localcontext\(\)\` as a context manager within the thread's target function, or explicitly configure \`getcontext\(\)\` at the start of each thread's work unit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:52:48.084116+00:00— report_created — created