Skip to content

Commit 33ea258

Browse files
committed
fix os.read to check signals
1 parent c36138c commit 33ea258

File tree

1 file changed

+14
-5
lines changed
  • crates/vm/src/stdlib

1 file changed

+14
-5
lines changed

crates/vm/src/stdlib/os.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,21 @@ pub(super) mod _os {
274274
}
275275

276276
#[pyfunction]
277-
fn read(fd: crt_fd::Borrowed<'_>, n: usize, vm: &VirtualMachine) -> io::Result<PyBytesRef> {
277+
fn read(fd: crt_fd::Borrowed<'_>, n: usize, vm: &VirtualMachine) -> PyResult<PyBytesRef> {
278278
let mut buffer = vec![0u8; n];
279-
let n = crt_fd::read(fd, &mut buffer)?;
280-
buffer.truncate(n);
281-
282-
Ok(vm.ctx.new_bytes(buffer))
279+
loop {
280+
match crt_fd::read(fd, &mut buffer) {
281+
Ok(n) => {
282+
buffer.truncate(n);
283+
return Ok(vm.ctx.new_bytes(buffer));
284+
}
285+
Err(e) if e.raw_os_error() == Some(libc::EINTR) => {
286+
vm.check_signals()?;
287+
continue;
288+
}
289+
Err(e) => return Err(e.into_pyexception(vm)),
290+
}
291+
}
283292
}
284293

285294
#[pyfunction]

0 commit comments

Comments
 (0)