Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit 37b7f1d

Browse files
committed
Use a timeout on fetching data, and handle failures gracefully.
Prevents a crash in the installer when the wifi connection is flaky.
1 parent f67323e commit 37b7f1d

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

esp32/modules/installer.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ugfx, badge, network, gc, time, urequests, appglue
1+
import ugfx, badge, network, gc, time, urequests, appglue, sys
22

33
# SHA2017 Badge installer
44
# V2 Thomas Roos
@@ -71,10 +71,19 @@ def list_apps(slug):
7171
ugfx.flush(ugfx.LUT_FULL)
7272

7373
try:
74-
f = urequests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug)
75-
packages = f.json()
76-
finally:
77-
f.close()
74+
f = urequests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug, timeout=30)
75+
try:
76+
packages = f.json()
77+
finally:
78+
f.close()
79+
except BaseException as e:
80+
print("[Installer] Failed to download list of eggs:")
81+
sys.print_exception(e)
82+
text.text("Download failed")
83+
ugfx.flush(ugfx.LUT_FULL)
84+
list_categories()
85+
gc.collect()
86+
return
7887

7988
for package in packages:
8089
options.add_item("%s rev. %s" % (package["name"], package["revision"]))
@@ -87,6 +96,7 @@ def list_apps(slug):
8796
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app('') if pushed else False)
8897

8998
show_description(True)
99+
ugfx.flush(ugfx.LUT_FULL)
90100
gc.collect()
91101

92102
def start_categories(pushed):
@@ -145,7 +155,7 @@ def list_categories():
145155
ugfx.input_init()
146156
draw_msg('Getting categories')
147157
try:
148-
f = urequests.get("https://badge.sha2017.org/eggs/categories/json")
158+
f = urequests.get("https://badge.sha2017.org/eggs/categories/json", timeout=30)
149159
categories = f.json()
150160
except:
151161
draw_msg('Failed!')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy