fix: retry python relative imports on errno 104

This commit is contained in:
Ruben Fiszel
2025-09-20 13:41:15 +00:00
parent 194887e97b
commit 81ff0dcd8c
2 changed files with 27 additions and 20 deletions
+26 -19
View File
@@ -51,25 +51,32 @@ class WindmillFinder(MetaPathFinder):
url = f"{os.environ.get('BASE_INTERNAL_URL')}/api/w/{os.environ.get('WM_WORKSPACE')}/scripts/raw/p/{script_path}.py{query_params}"
req = urllib.request.Request(url, None, headers)
try:
req_start = time.time()
with urllib.request.urlopen(req) as response:
os.makedirs(folder, exist_ok=True)
r = response.read().decode("utf-8")
if r == "WINDMILL_IS_FOLDER":
return ModuleSpec(name, WindmillLoader(name))
with open(fullpath, "w+") as f:
f.write(r)
return ModuleSpec(name, SourceFileLoader(name, fullpath))
except urllib.error.HTTPError as e:
duration = time.time() - req_start
if e.code != 404:
print(f"Error fetching script {script_path}: HTTP {e.code} - {e.reason} - {duration}s")
return ModuleSpec(name, WindmillLoader(name))
except Exception as e:
duration = time.time() - req_start
print(f"Error fetching script {script_path}: {e} - {duration}s")
return ModuleSpec(name, WindmillLoader(name))
for attempt in range(4): # 0, 1, 2, 3 = up to 3 retries
try:
req_start = time.time()
with urllib.request.urlopen(req) as response:
os.makedirs(folder, exist_ok=True)
r = response.read().decode("utf-8")
if r == "WINDMILL_IS_FOLDER":
return ModuleSpec(name, WindmillLoader(name))
with open(fullpath, "w+") as f:
f.write(r)
return ModuleSpec(name, SourceFileLoader(name, fullpath))
except urllib.error.HTTPError as e:
duration = time.time() - req_start
if e.code != 404:
print(f"Error fetching script {script_path}: HTTP {e.code} - {e.reason} - {duration}s")
return ModuleSpec(name, WindmillLoader(name))
except Exception as e:
duration = time.time() - req_start
# Check if this is errno 104 (Connection reset by peer) and we have retries left
if (hasattr(e, 'errno') and e.errno == 104) and attempt < 3:
print(f"Connection reset (errno 104) fetching script {script_path}, retrying in 3s (attempt {attempt + 1}/3)")
time.sleep(3)
continue
print(f"Error fetching script {script_path}: {e} - {duration}s")
return ModuleSpec(name, WindmillLoader(name))
+1 -1
View File
@@ -1338,7 +1338,7 @@
<!-- svelte-ignore a11y_click_events_have_key_events -->
<button
class="absolute {password || extra?.['password'] == true
? 'right-16 top-1.5 '
? 'right-16 top-1.5'
: 'right-1 top-1'} opacity-0 group-hover:opacity-100 duration-200 py-1 min-w-min !px-2 items-center text-gray-800 bg-surface-secondary border rounded center-center hover:bg-gray-300 transition-all cursor-pointer"
onclick={() => {
pickForField = label