minor wording tweaks and a docstring

This commit is contained in:
Damien Elmes 2021-11-23 12:17:10 +10:00
parent 6d0f7e7f05
commit 675155e025
2 changed files with 10 additions and 5 deletions

View File

@ -1680,7 +1680,7 @@ title="{}" {}>{}</button>""".format(
def setupMediaServer(self) -> None:
self.mediaServer = aqt.mediasrv.MediaServer(self)
self.mediaServer.start()
self.mediaServer.wait_start_up()
self.mediaServer.await_ready()
def baseHTML(self) -> str:
return f'<base href="{self.serverURL()}">'

View File

@ -141,11 +141,16 @@ class MediaServer(threading.Thread):
self._ready.wait()
return str(self.server.effective_host) # type: ignore
def wait_start_up(self) -> None:
self.check_server(self.getHost(), self.getPort(), "/favicon.ico")
def await_ready(self) -> None:
"""Block until webserver can respond to requests.
Potentially solves a race condition at startup where some resources
fail to load.
https://github.com/ankitects/anki/pull/1369
"""
self._check_server(self.getHost(), self.getPort(), "/favicon.ico")
@classmethod
def check_server(
def _check_server(
cls,
host: str,
port: int,
@ -160,7 +165,7 @@ class MediaServer(threading.Thread):
for index in range(retries):
if devMode or index > 0:
print(
f"{datetime.datetime.now()} waiting media server on {host}:{port}..."
f"{datetime.datetime.now()} awaiting media server on {host}:{port}..."
)
try:
with http_connection(host, port, timeout=timeout) as conn: