diff options
| author | Danilo M. <danix@danix.xyz> | 2026-05-05 10:51:56 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-05-05 10:51:56 +0200 |
| commit | 54ad3e37c6e9d2242f932c192119dd6de64966cf (patch) | |
| tree | 84c7018152825a63c2f6b009f18634a8585d996a /workers | |
| parent | 48b84da95d0736124f8be6849aa32df31bdb29aa (diff) | |
| download | publisher-54ad3e37c6e9d2242f932c192119dd6de64966cf.tar.gz publisher-54ad3e37c6e9d2242f932c192119dd6de64966cf.zip | |
feat: check OLLAMA_HOST reachability before starting translationv1.6
Non-blocking QThread check hits /api/tags on the resolved ollama host
before launching TranslationWorker. Shows QMessageBox.warning() if
unreachable; proceeds silently if reachable. Adds ollama_host field to
Config with env-var fallback to http://localhost:11434.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'workers')
| -rw-r--r-- | workers/ollama_check_worker.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/workers/ollama_check_worker.py b/workers/ollama_check_worker.py new file mode 100644 index 0000000..5f47492 --- /dev/null +++ b/workers/ollama_check_worker.py @@ -0,0 +1,19 @@ +from __future__ import annotations +import urllib.request +from PyQt6.QtCore import QThread, pyqtSignal + + +class OllamaCheckWorker(QThread): + reachable = pyqtSignal(bool, str) # (ok, url_tried) + + def __init__(self, host_url: str, timeout: int = 4, parent=None): + super().__init__(parent) + self._url = host_url.rstrip("/") + "/api/tags" + self._timeout = timeout + + def run(self): + try: + urllib.request.urlopen(self._url, timeout=self._timeout) + self.reachable.emit(True, self._url) + except Exception: + self.reachable.emit(False, self._url) |
