Skip to content

Commit

Permalink
Fix httpx timeout issues (#7707)
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyaboulton committed Mar 15, 2024
1 parent bc61ff6 commit 28342a2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-bikes-hear.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Fix httpx timeout issues
4 changes: 3 additions & 1 deletion gradio/blocks.py
Expand Up @@ -2122,7 +2122,9 @@ def reverse(text):
if not wasm_utils.IS_WASM:
# Cannot run async functions in background other than app's scope.
# Workaround by triggering the app endpoint
httpx.get(f"{self.local_url}startup-events", verify=ssl_verify)
httpx.get(
f"{self.local_url}startup-events", verify=ssl_verify, timeout=None
)
else:
# NOTE: One benefit of the code above dispatching `startup_events()` via a self HTTP request is
# that `self._queue.start()` is called in another thread which is managed by the HTTP server, `uvicorn`
Expand Down
2 changes: 1 addition & 1 deletion gradio/networking.py
Expand Up @@ -253,6 +253,6 @@ def url_ok(url: str) -> bool:
if r.status_code in (200, 401, 302): # 401 or 302 if auth is set
return True
time.sleep(0.500)
except (ConnectionError, httpx.ConnectError):
except (ConnectionError, httpx.ConnectError, httpx.TimeoutException):
return False
return False
2 changes: 1 addition & 1 deletion gradio/utils.py
Expand Up @@ -305,7 +305,7 @@ def download_if_url(article: str) -> str:
response = httpx.get(article, timeout=3)
if response.status_code == httpx.codes.OK: # pylint: disable=no-member
article = response.text
except (httpx.InvalidURL, httpx.RequestError):
except (httpx.InvalidURL, httpx.RequestError, httpx.TimeoutException):
pass

return article
Expand Down

0 comments on commit 28342a2

Please sign in to comment.