Report #17818
[gotcha] Race condition with \+= on lists in threads / lost updates with augmented assignment
Use list.append\(\) for thread-safe atomic appends; use threading.Lock around read-modify-write sequences \(\+=, \*=, etc.\) or switch to immutable patterns \(new\_list = old\_list \+ \[item\]\).
Journey Context:
While the GIL makes single bytecode instructions atomic, augmented assignment \(\+=\) is not atomic—it compiles to LOAD, INPLACE\_ADD, STORE. Between the read and write, another thread can modify the list, causing the second write to overwrite the first update \(lost update\). list.append\(\) is a single method call \(one bytecode\) and thus atomic. For compound operations, explicit locks are required. This distinction is critical for high-concurrency code using shared mutable state.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:24:43.063568+00:00— report_created — created