Skip to content
Merged
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
4 changes: 0 additions & 4 deletions Lib/test/test_file_eintr.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ def test_readall(self):
class CTestFileIOSignalInterrupt(TestFileIOSignalInterrupt, unittest.TestCase):
modname = '_io'

@unittest.expectedFailure # TODO: RUSTPYTHON; - _io.FileIO.readall uses read_to_end which differs from _pyio.FileIO.readall
def test_readall(self):
return super().test_readall()

class PyTestFileIOSignalInterrupt(TestFileIOSignalInterrupt, unittest.TestCase):
modname = '_pyio'

Expand Down
40 changes: 24 additions & 16 deletions crates/vm/src/stdlib/_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6417,25 +6417,33 @@ mod fileio {
bytes.shrink_to_fit();
bytes
} else {
let mut bytes = vec![];
// Loop on EINTR (PEP 475)
let mut bytes = Vec::new();
let mut used = 0;
// Read one syscall at a time so EINTR reaches the Python
// signal handler instead of being retried inside read_to_end.
loop {
match vm.allow_threads(|| host_io::read_all(handle, &mut bytes)) {
Ok(()) => break,
Err(e) if host_io::is_interrupted_error(&e) => {
vm.check_signals()?;
continue;
}
// Non-blocking mode: return None if EAGAIN (only if no data read yet)
Err(e) if host_io::is_would_block_error(&e) => {
if bytes.is_empty() {
return Ok(None);
}
break;
}
Err(e) => return Err(FileIO::io_error(zelf, e, vm)),
if used == bytes.len() {
// Match FileIO's amortized growth while leaving at least
// one byte for the read that detects EOF.
let growth = if used > 65_536 { used >> 3 } else { used + 256 }.max(8192);
let size = used.checked_add(growth).filter(|&n| isize::try_from(n).is_ok())
.ok_or_else(|| vm.new_overflow_error(
"unbounded read returned more bytes than a Python bytes object can hold"
))?;
bytes
.try_reserve_exact(growth)
.map_err(|_| vm.no_memory_error())?;
bytes.resize(size, 0);
}
match FileIO::read_once_into(zelf, handle, &mut bytes[used..], vm)? {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Retire the expected-failure marker for the repaired EINTR test

On POSIX, the signal-aware call now lets the read() phase of CTestFileIOSignalInterrupt.test_readall complete, but Lib/test/test_file_eintr.py:189 still decorates the entire test with @unittest.expectedFailure. Consequently, a correct run is recorded as an unexpected success, which Lib/unittest/result.py::wasSuccessful and the regrtest runner treat as a failing suite. Validate the repaired test and remove its obsolete decorator/TODO alongside this fix so that test_file_eintr can pass.

AGENTS.md reference: AGENTS.md:L100-L100

Useful? React with 👍 / 👎.

Some(0) => break,
Some(n) => used += n,
None if used == 0 => return Ok(None),
None => break,
}
}
bytes.truncate(used);
bytes.shrink_to_fit();
bytes
};

Expand Down
Loading