Skip to content

gh-152754: Fix crash when an os.scandir iterator is shared between threads#153402

Open
deadlovelll wants to merge 1 commit into
python:mainfrom
deadlovelll:gh-152754-os-race
Open

gh-152754: Fix crash when an os.scandir iterator is shared between threads#153402
deadlovelll wants to merge 1 commit into
python:mainfrom
deadlovelll:gh-152754-os-race

Conversation

@deadlovelll

Copy link
Copy Markdown
Contributor

Fix crash when an os.scandir iterator is shared between threads

for more details see gh-152754

@nascheme

nascheme commented Jul 9, 2026

Copy link
Copy Markdown
Member

I have some concerns about this approach. Using critical sections is probably not the right tool. We still want to release the GIL when doing IO, i.e. the Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS blocks. I created a revised PR based on this one that uses a mutex instead. With the mutex it's easier to confirm that everything is safe (critical section can be released depending on what you call inside of it) and it's pretty easy to also confirm there is no deadlock risk (always a concern when using a plain mutex).

BTW, for the unit test, you should use threading_helper.run_concurrently().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants