Skip to content

Add timeout to requests calls #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/scripts/close_nonexistent_disable_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def query_rockset(

def download_log_worker(temp_dir: str, id: int, name: str) -> None:
url = f"https://ossci-raw-job-status.s3.amazonaws.com/log/{id}"
data = requests.get(url).text
data = requests.get(url, timeout=60).text
with open(f"{temp_dir}/{name.replace('/', '_')} {id}.txt", "x") as f:
f.write(data)

Expand All @@ -103,12 +103,12 @@ def close_issue(num: int) -> None:
f"https://api.github.com/repos/pytorch/pytorch/issues/{num}/comments",
data=json.dumps({"body": CLOSING_COMMENT}),
headers=headers,
)
timeout=60)
requests.patch(
f"https://api.github.com/repos/pytorch/pytorch/issues/{num}",
data=json.dumps({"state": "closed"}),
headers=headers,
)
timeout=60)


def check_if_exists(
Expand Down Expand Up @@ -147,7 +147,7 @@ def check_if_exists(

if __name__ == "__main__":
args = parse_args()
disabled_tests_json = json.loads(requests.get(DISABLED_TESTS_JSON).text)
disabled_tests_json = json.loads(requests.get(DISABLED_TESTS_JSON, timeout=60).text)

all_logs = []
jobs = query_rockset(LOGS_QUERY)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/dynamo/ci_expected_accuracy/update_expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def query_job_sha(repo, sha):
]
}

r = requests.post(url=ARTIFACTS_QUERY_URL, json=params)
r = requests.post(url=ARTIFACTS_QUERY_URL, json=params, timeout=60)
data = r.json()
return data["results"]

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/upload_scribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def upload(self, messages):
]
),
},
)
timeout=60)
print(r.text)
r.raise_for_status()

Expand Down
2 changes: 1 addition & 1 deletion ios/TestApp/run_on_aws_devicefarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def upload_file(

with open(filename, "rb") as file_stream:
print(f"Uploading {filename} to Device Farm as {upload_name}...")
r = requests.put(upload_url, data=file_stream, headers={"content-type": mime})
r = requests.put(upload_url, data=file_stream, headers={"content-type": mime}, timeout=60)
if not r.ok:
raise Exception(f"Couldn't upload {filename}: {r.reason}")

Expand Down
4 changes: 2 additions & 2 deletions scripts/compile_tests/download_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def subdir_path(config):

# This page lists all artifacts.
listings = requests.get(
f"https://hud.pytorch.org/api/artifacts/s3/{workflow_run_id}"
).json()
f"https://hud.pytorch.org/api/artifacts/s3/{workflow_run_id}",
timeout=60).json()

def download_report(job_name, subdir):
job_id = workflow_jobs[job_name]
Expand Down
4 changes: 2 additions & 2 deletions scripts/release_notes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def get_token():

def run_query(query):
request = requests.post(
"https://api.github.com/graphql", json={"query": query}, headers=headers
)
"https://api.github.com/graphql", json={"query": query}, headers=headers,
timeout=60)
if request.status_code == 200:
return request.json()
else:
Expand Down
2 changes: 1 addition & 1 deletion tools/alerts/create_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __repr__(self) -> str:


def fetch_hud_data(repo: str, branch: str) -> Any:
response = requests.get(f"https://hud.pytorch.org/api/hud/{repo}/{branch}/0")
response = requests.get(f"https://hud.pytorch.org/api/hud/{repo}/{branch}/0", timeout=60)
response.raise_for_status()
hud_data = json.loads(response.text)
return (hud_data["jobNames"], hud_data["shaGrid"])
Expand Down
8 changes: 4 additions & 4 deletions tools/stats/upload_stats_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def _get_artifact_urls(prefix: str, workflow_run_id: int) -> Dict[Path, str]:
"""Get all workflow artifacts with 'test-report' in the name."""
response = requests.get(
f"{PYTORCH_REPO}/actions/runs/{workflow_run_id}/artifacts?per_page=100",
)
timeout=60)
artifacts = response.json()["artifacts"]
while "next" in response.links.keys():
response = requests.get(
response.links["next"]["url"], headers=_get_request_headers()
)
response.links["next"]["url"], headers=_get_request_headers(),
timeout=60)
artifacts.extend(response.json()["artifacts"])

artifact_urls = {}
Expand Down Expand Up @@ -69,7 +69,7 @@ def _download_artifact(

print(f"Downloading {artifact_name}")

response = requests.get(artifact_url, headers=_get_request_headers())
response = requests.get(artifact_url, headers=_get_request_headers(), timeout=60)
with open(artifact_name, "wb") as f:
f.write(response.content)
return artifact_name
Expand Down
Loading