Report #76369
[gotcha] decimal precision lost silently when using multiprocessing Process
Explicitly reconfigure decimal.getcontext\(\) inside the target function of each Process or use a Pool initializer; never assume the parent's decimal context \(precision, rounding\) is inherited by child processes.
Journey Context:
The decimal module's context is stored in thread-local storage. When multiprocessing spawns a child process \(especially with 'spawn' start method on macOS/Windows or 'forkserver'\), the child receives a fresh memory space with default decimal contexts \(28 places, ROUND\_HALF\_EVEN\). Developers set precision in the parent main thread, launch processes, and get silent data corruption as high-precision calculations revert to 28 digits. The fix is not to set context in global module scope \(which runs in parent only\) but to pass precision as an argument and call localcontext\(\) or setcontext\(\) inside the worker. This is distinct from threading where Thread inherits the context of the creator.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:46:50.758276+00:00— report_created — created