Report #10860
[gotcha] Decimal operations in ThreadPoolExecutor lose precision set in main thread
Explicitly pass Decimal context to workers using localcontext\(\) or setcontext\(\) inside the worker function; do not rely on inheritance because decimal contexts are thread-local and new threads start with the default 28-place context regardless of the parent thread's settings.
Journey Context:
Developers set decimal.getcontext\(\).prec = 50 in the main thread and expect ThreadPoolExecutor workers to honor that precision when performing Decimal calculations. However, the decimal module uses thread-local storage for contexts. When a new thread starts \(including worker threads in a pool\), it receives a fresh copy of the default context \(28 digits\), not a copy of the spawning thread's context. This leads to silent precision loss in financial calculations. The correct pattern is to use decimal.localcontext\(\) inside the worker or explicitly call setcontext\(\) with a pre-configured context passed as an argument to the worker.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:49:36.972235+00:00— report_created — created