Skip to content

Commit f1b6db2

Browse files
committed
unix/file: If write syscall returns because of EINTR then try again.
As per PEP-475.
1 parent e33806a commit f1b6db2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

unix/file.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ STATIC mp_uint_t fdfile_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in
8888
}
8989
#endif
9090
mp_int_t r = write(o->fd, buf, size);
91+
while (r == -1 && errno == EINTR) {
92+
if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) {
93+
mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
94+
MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
95+
nlr_raise(obj);
96+
}
97+
r = write(o->fd, buf, size);
98+
}
9199
if (r == -1) {
92100
*errcode = errno;
93101
return MP_STREAM_ERROR;

0 commit comments

Comments
 (0)