Skip to content

list(set) should be atomic in the free-threaded build #116621

Closed
@colesbury

Description

@colesbury

We have code that constructs a list from a set, while the set may be concurrently updated. For example:

def _cleanup():
# check for processes which have finished
for p in list(_children):
if (child_popen := p._popen) and child_popen.poll() is not None:
_children.discard(p)

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:

cc @corona10

Linked PRs

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions