Skip to content

Commit 354bfc6

Browse files
committed
fix (server): edited endpoint to request to verify if server is ready,
added ResourceWarning for unclosed server in LanguageTool class
1 parent 2adf85b commit 354bfc6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

language_tool_python/server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import subprocess
1111
import time
1212
import urllib.parse
13+
import warnings
1314
from typing import Any, Dict, List, Optional, Set
1415

1516
import psutil
@@ -201,8 +202,9 @@ def __del__(self) -> None:
201202
ensures that the `close` method is called to release any resources
202203
or perform any necessary cleanup.
203204
"""
204-
205-
self.close()
205+
if self._server_is_alive():
206+
warnings.warn("unclosed server", ResourceWarning, stacklevel=2)
207+
self.close()
206208

207209
def __repr__(self) -> str:
208210
"""
@@ -605,7 +607,7 @@ def _start_local_server(self) -> None:
605607
def _wait_for_server_ready(self, timeout: int = 15) -> None:
606608
"""
607609
Wait for the LanguageTool server to become ready and responsive.
608-
This method polls the server's ``/languages`` endpoint until it responds
610+
This method polls the server's ``/healthcheck`` endpoint until it responds
609611
successfully or until the timeout is reached. It also monitors the server
610612
process to detect early exits.
611613
@@ -616,7 +618,7 @@ def _wait_for_server_ready(self, timeout: int = 15) -> None:
616618
or if the server does not become ready within the specified
617619
timeout period.
618620
"""
619-
url = urllib.parse.urljoin(self._url, "languages")
621+
url = urllib.parse.urljoin(self._url, "healthcheck")
620622
start = time.time()
621623

622624
while time.time() - start < timeout:

0 commit comments

Comments
 (0)