Skip to content

Commit 2e6095d

Browse files
authored
Added the ability to specify a timeout for Libretranslate (#146)
1 parent cef921c commit 2e6095d

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

config/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
with open(BASE_DIR / "pyproject.toml", "rb") as f:
2929
pyproject = tomllib.load(f)
3030
VERSION = pyproject["project"]["version"]
31+
LT_TIMEOUT=int(os.environ.get("LT_TIMEOUT", '5'))
3132

3233
X_FRAME_OPTIONS = os.environ.get("X_FRAME_OPTIONS", "DENY")
3334

core/models/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def _api_request(
615615
req.add_header("Content-Type", "application/x-www-form-urlencoded")
616616
req.add_header("User-Agent", "LibreTranslateAgent/1.0")
617617

618-
with request.urlopen(req, timeout=5) as response:
618+
with request.urlopen(req, timeout=settings.LT_TIMEOUT) as response:
619619
response_str = response.read().decode("utf-8")
620620
return json.loads(response_str)
621621
except Exception as e:

0 commit comments

Comments
 (0)