Skip to content

Commit 6e73143

Browse files
committed
stream: Add compliant handling of non-blocking readall().
1 parent a592104 commit 6e73143

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

py/stream.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
119119
while (true) {
120120
machine_int_t out_sz = o->type->stream_p->read(self_in, p, current_read, &error);
121121
if (out_sz == -1) {
122+
if (is_nonblocking_error(error)) {
123+
// With non-blocking streams, we read as much as we can.
124+
// If we read nothing, return None, just like read().
125+
// Otherwise, return data read so far.
126+
if (total_size == 0) {
127+
return mp_const_none;
128+
}
129+
break;
130+
}
122131
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error));
123132
}
124133
if (out_sz == 0) {

0 commit comments

Comments
 (0)