Closed
Description
We have code that constructs a list from a set, while the set may be concurrently updated. For example:
cpython/Lib/multiprocessing/process.py
Lines 61 to 65 in 44f9a84
This is a fairly common pattern currently, but in the free-threaded build, this may lead to RuntimeError: Set changed size during iteration
. We should make it so that list(set)
locks the set to avoid the error and so that the list contains a consistent copy of the set.
For additional context, see the following code from the nogil-3.12 fork:
- https://github.com/colesbury/nogil-3.12/blob/cedde4f5ec3759ad723c89d44738776f362df564/Objects/listobject.c#L1223-L1243
- https://github.com/colesbury/nogil-3.12/blob/cedde4f5ec3759ad723c89d44738776f362df564/Objects/listobject.c#L1372-L1381
cc @corona10