Please take race conditions seriously when discussing threading

Sorry, I was wrong about this. I saw a discussion about making the builtin iterators (map, range, iter) threadsafe and thought that had happened for 3.14, but I misremembered and doesn’t appear to have.

From source diving to verify: The builtin primitive builtin data types: int, str, bytes, dict, set, frozenlist, list, and tuple are mostly threadsafe, with the exception of sharing and reusing an iterator created from them across threads (iter, .keys, etc). In addition to that, collections.deque is also threadsafe aside from iteration. Of the mutable ones of those, there are safe ways to use them and unsafe ways to use them outside of iteration, which isn’t currently safe.

None of this is a guarantee currently, and it is specific to CPython, but it would be hard to imagine a world where anyone argues to make these less safe than they currently are when discussion of making iteration safe for these is currently happening

I agree with people above, it would be better if some of these things became language level guarantees, but the most that many things can offer is consistency, not race-free behavior. Race free behavior involves application design.

1 Like