I know that the builtin set type in python is not generally threadsafe, but this answer claims that it is safe to call pop() from two competing threads. Sure, you might get an exception, but your data isn’t corrupted. I can’t seem to find a doc that validates this claim. Is it true? Documentation, please!
Share
If you look at the
set.popmethod in the CPython source you’ll see that it doesn’t release the GIL.That means that only one
set.popwill ever be happening at a time within a CPython process.Since
set.popchecks if the set is empty, you can’t cause anything but anIndexErrorby trying to pop from an empty set.So no, you can’t corrupt the data by popping from a set in multiple threads with CPython.