summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-05-29 09:53:04 +0100
committerDamien George <damien.p.george@gmail.com>2016-05-29 09:53:04 +0100
commit6707fc94ae1b3b4227c514109b31c2e2eaba67e8 (patch)
treef1c9f11229d0ed493c426d2d81d27cbb74595315
parent84381fa0fc3b8e461042710c5e7c348367ec4772 (diff)
downloadmicropython-6707fc94ae1b3b4227c514109b31c2e2eaba67e8.tar.gz
micropython-6707fc94ae1b3b4227c514109b31c2e2eaba67e8.zip
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.
-rw-r--r--esp8266/modnetwork.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/esp8266/modnetwork.c b/esp8266/modnetwork.c
index a0758a0d47..c0763ce0eb 100644
--- a/esp8266/modnetwork.c
+++ b/esp8266/modnetwork.c
@@ -172,7 +172,17 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) {
mp_obj_t list = mp_obj_new_list(0, NULL);
esp_scan_list = &list;
wifi_station_scan(NULL, (scan_done_cb_t)esp_scan_cb);
- ETS_POLL_WHILE(esp_scan_list != NULL);
+ while (esp_scan_list != NULL) {
+ // our esp_scan_cb is called via ets_loop_iter so it's safe to set the
+ // esp_scan_list variable to NULL without disabling interrupts
+ if (MP_STATE_VM(mp_pending_exception) != NULL) {
+ esp_scan_list = NULL;
+ mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
+ MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
+ nlr_raise(obj);
+ }
+ ets_loop_iter();
+ }
if (list == MP_OBJ_NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "scan failed"));
}