by monopede · 14y ago · 0 comments
x += 5
may be fine depending on whether it is implemented as a single bytecode instruction or not. However, more complicated updates are still subject to races: x = somefunction(x)
It is only safe if you use: with thread.atomic: x = somefunction(x)
Having a serialisation doesn't mean it's the right serialisation.That said, the fundamental problem is shared mutable state, and I don't see an easy way around that in Python. In that sense, this is probably easiest to work with.