Skip to content

Commit

Permalink
Retry on transient error codes in preload (#5982)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin authored Mar 30, 2022
1 parent 8906cab commit b9902d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions distributed/preloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import os
import shutil
import sys
import urllib.request
from collections.abc import Iterable
from importlib import import_module
from types import ModuleType
from typing import TYPE_CHECKING, cast

import click
import urllib3

from dask.utils import tmpfile

Expand Down Expand Up @@ -131,9 +131,17 @@ def _download_module(url: str) -> ModuleType:
logger.info("Downloading preload at %s", url)
assert is_webaddress(url)

request = urllib.request.Request(url, method="GET")
response = urllib.request.urlopen(request)
source = response.read().decode()
with urllib3.PoolManager() as http:
response = http.request(
method="GET",
url=url,
retries=urllib3.util.Retry(
status_forcelist=[429, 504, 503, 502],
backoff_factor=0.2,
),
)

source = response.data

compiled = compile(source, url, "exec")
module = ModuleType(url)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ sortedcontainers !=2.0.0, !=2.0.1
tblib >= 1.6.0
toolz >= 0.8.2
tornado >= 6.0.3
urllib3
zict >= 0.1.3
pyyaml

0 comments on commit b9902d7

Please sign in to comment.