Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Lib/test/test_free_threading/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@

@threading_helper.requires_working_threading()
class TestOs(unittest.TestCase):
def test_listdir_during_gc(self):
import gc
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as directory:
expected = {f"entry_{n}" for n in range(32)}
for name in expected:
Path(directory, name).touch()

def worker():
for _ in range(256):
gc.collect()
self.assertEqual(set(os.listdir(directory)), expected)

run_concurrently(worker, nthreads=4)

@unittest.skipUnless(sysconfig.get_config_var('_Py_HAVE_STRERROR_R'),
'need _Py_HAVE_STRERROR_R macro')
def test_strerror(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Preserve ``errno`` across thread-state attachment in release builds,
preventing spurious directory I/O errors on free-threaded builds during
concurrent garbage collection.
4 changes: 0 additions & 4 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2383,11 +2383,9 @@ tstate_wait_attach(PyThreadState *tstate)
void
_PyThreadState_Attach(PyThreadState *tstate)
{
#if defined(Py_DEBUG)
// This is called from PyEval_RestoreThread(). Similar
// to it, we need to ensure errno doesn't change.
int err = errno;
#endif

_Py_EnsureTstateNotNULL(tstate);
if (current_fast_get() != NULL) {
Expand Down Expand Up @@ -2434,9 +2432,7 @@ _PyThreadState_Attach(PyThreadState *tstate)
_PyStats_Attach((_PyThreadStateImpl *)tstate);
#endif

#if defined(Py_DEBUG)
errno = err;
#endif
}

static void
Expand Down
Loading