Report #62031
[gotcha] Why does my Decimal precision setting get lost or behave inconsistently in multi-threaded applications?
Use \`localcontext\(\)\` as a context manager for temporary changes, or explicitly pass the context to \`Decimal\` operations. Do not rely on \`getcontext\(\)\` being global; it is thread-local.
Journey Context:
The \`decimal\` module's \`getcontext\(\)\` returns a thread-local context object. Changing precision or rounding in one thread does not affect other threads, which is usually desired but surprising if you expect a global application setting. The footgun occurs when a main thread sets precision, then spawns workers that inherit the default context, not the modified one, leading to silent precision loss in calculations. Use \`localcontext\(\)\` to ensure temporary settings don't leak, and explicitly pass \`context=\` to \`Decimal\` constructors or arithmetic methods when cross-thread consistency is required.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:36:16.314639+00:00— report_created — created