Skip to content

Commit 6707fc9

Browse files
committed
esp8266/modnetwork: Allow to press ctrl-C while scan() is running.
Ctrl-C will raise a KeyboardInterrupt and stop the scan (although it will continue to run in the background, it won't report anything). If interrupted, and another scan() is started before the old one completes in the background, then the second scan will fail with an OSError.
1 parent 84381fa commit 6707fc9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

esp8266/modnetwork.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,17 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) {
172172
mp_obj_t list = mp_obj_new_list(0, NULL);
173173
esp_scan_list = &list;
174174
wifi_station_scan(NULL, (scan_done_cb_t)esp_scan_cb);
175-
ETS_POLL_WHILE(esp_scan_list != NULL);
175+
while (esp_scan_list != NULL) {
176+
// our esp_scan_cb is called via ets_loop_iter so it's safe to set the
177+
// esp_scan_list variable to NULL without disabling interrupts
178+
if (MP_STATE_VM(mp_pending_exception) != NULL) {
179+
esp_scan_list = NULL;
180+
mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
181+
MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
182+
nlr_raise(obj);
183+
}
184+
ets_loop_iter();
185+
}
176186
if (list == MP_OBJ_NULL) {
177187
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "scan failed"));
178188
}

0 commit comments

Comments
 (0)