Skip to content

Commit de0dda9

Browse files
committed
Ensure background tasks are serviced during a lengthy sendall
1 parent 3b7fecc commit de0dda9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

shared-bindings/socketpool/Socket.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "py/mperrno.h"
3838

3939
#include "shared/netutils/netutils.h"
40+
#include "shared/runtime/interrupt_char.h"
4041

4142
//| class Socket:
4243
//| """TCP, UDP and RAW socket. Cannot be created directly. Instead, call
@@ -283,6 +284,13 @@ STATIC mp_obj_t _socketpool_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
283284
}
284285
bufinfo.len -= ret;
285286
bufinfo.buf += ret;
287+
if (bufinfo.len > 0) {
288+
RUN_BACKGROUND_TASKS;
289+
// Allow user to break out of sendall with a KeyboardInterrupt.
290+
if (mp_hal_is_interrupted()) {
291+
return 0;
292+
}
293+
}
286294
}
287295
return mp_const_none;
288296
}

0 commit comments

Comments
 (0)