From ed5aeff86a6af57e4f7c8ea8e4dad98013c889cf Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Sat, 25 Jan 2025 04:06:46 +0000 Subject: [PATCH] Add timeout to `requests` calls --- .github/scripts/close_nonexistent_disable_issues.py | 8 ++++---- benchmarks/dynamo/ci_expected_accuracy/update_expected.py | 2 +- benchmarks/upload_scribe.py | 2 +- ios/TestApp/run_on_aws_devicefarm.py | 2 +- scripts/compile_tests/download_reports.py | 4 ++-- scripts/release_notes/common.py | 4 ++-- tools/alerts/create_alerts.py | 2 +- tools/stats/upload_stats_lib.py | 8 ++++---- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/scripts/close_nonexistent_disable_issues.py b/.github/scripts/close_nonexistent_disable_issues.py index bef459a3a8d0..3ca7ff4ca5a2 100644 --- a/.github/scripts/close_nonexistent_disable_issues.py +++ b/.github/scripts/close_nonexistent_disable_issues.py @@ -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) @@ -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( @@ -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) diff --git a/benchmarks/dynamo/ci_expected_accuracy/update_expected.py b/benchmarks/dynamo/ci_expected_accuracy/update_expected.py index 5d73cf658c17..64f0f7b0a1a7 100644 --- a/benchmarks/dynamo/ci_expected_accuracy/update_expected.py +++ b/benchmarks/dynamo/ci_expected_accuracy/update_expected.py @@ -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"] diff --git a/benchmarks/upload_scribe.py b/benchmarks/upload_scribe.py index 0c1f9448b15b..a77b754edbc6 100644 --- a/benchmarks/upload_scribe.py +++ b/benchmarks/upload_scribe.py @@ -64,7 +64,7 @@ def upload(self, messages): ] ), }, - ) + timeout=60) print(r.text) r.raise_for_status() diff --git a/ios/TestApp/run_on_aws_devicefarm.py b/ios/TestApp/run_on_aws_devicefarm.py index 5ac692ea496f..8aabe782c5c1 100755 --- a/ios/TestApp/run_on_aws_devicefarm.py +++ b/ios/TestApp/run_on_aws_devicefarm.py @@ -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}") diff --git a/scripts/compile_tests/download_reports.py b/scripts/compile_tests/download_reports.py index 59c5d707ef13..44f4c86d6d49 100644 --- a/scripts/compile_tests/download_reports.py +++ b/scripts/compile_tests/download_reports.py @@ -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] diff --git a/scripts/release_notes/common.py b/scripts/release_notes/common.py index aa7d2e658e64..12bfdb42f4d6 100644 --- a/scripts/release_notes/common.py +++ b/scripts/release_notes/common.py @@ -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: diff --git a/tools/alerts/create_alerts.py b/tools/alerts/create_alerts.py index 33e595f98dad..3e49622a6c3c 100644 --- a/tools/alerts/create_alerts.py +++ b/tools/alerts/create_alerts.py @@ -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"]) diff --git a/tools/stats/upload_stats_lib.py b/tools/stats/upload_stats_lib.py index 45ea6ba39fd5..4f858ccf379c 100644 --- a/tools/stats/upload_stats_lib.py +++ b/tools/stats/upload_stats_lib.py @@ -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 = {} @@ -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