style: shorten code comments to one line

This commit is contained in:
2026-06-07 18:47:44 +02:00
parent 3d96e5060f
commit b2f85591ce
6 changed files with 14 additions and 36 deletions

View File

@@ -396,9 +396,7 @@ def ensure(*names):
f"Set '{gd_key}' in the YAML config to override." f"Set '{gd_key}' in the YAML config to override."
) )
elif not tm.gd(gd_key): elif not tm.gd(gd_key):
# Publish the resolved interpreter so test scripts can reference # Publish resolved path so test scripts can use $(python_bin)/$(lua_bin).
# $(python_bin) / $(lua_bin) regardless of how testium was launched
# (e.g. GUI, where no -d override is passed).
tm.setgd(gd_key, path) tm.setgd(gd_key, path)
if missing: if missing:
raise ETUMRuntimeError( raise ETUMRuntimeError(

View File

@@ -116,15 +116,13 @@ class LuaProcessBase:
restore_signals=False, restore_signals=False,
**popen_kwargs, **popen_kwargs,
) )
# Route subprocess stdout/stderr into the parent's log and read the # Forward subprocess output to the log and read the startup port sentinel.
# startup port sentinel before connecting.
holder = drain_and_read_port(self._process, prefix="[lua_func] ") holder = drain_and_read_port(self._process, prefix="[lua_func] ")
self._port = wait_for_port( self._port = wait_for_port(
self._process, holder, tm.gd("proc_start_timeout", 30) self._process, holder, tm.gd("proc_start_timeout", 30)
) )
if self._port is None: if self._port is None:
# Worker died before announcing its port: tear down fully so a # Worker died before announcing its port: reset so a later start() retries clean.
# later start() (e.g. a reused context_id engine) can retry cleanly.
self.stop() self.stop()
self.join() self.join()
return return

View File

@@ -77,8 +77,7 @@ def drain_and_read_port(process, prefix=""):
pipe.close() pipe.close()
except Exception: except Exception:
pass pass
# Unblock the waiter on EOF even if the sentinel never came. holder["evt"].set() # unblock waiter on EOF even without sentinel
holder["evt"].set()
if process.stdout is not None: if process.stdout is not None:
threading.Thread( threading.Thread(
@@ -104,7 +103,6 @@ def wait_for_port(process, holder, deadline):
if holder["port"] is not None: if holder["port"] is not None:
break break
if process.poll() is not None: if process.poll() is not None:
# Child exited; give the reader a moment to flush a trailing line. holder["evt"].wait(0.2) # child exited; let the reader flush a trailing line
holder["evt"].wait(0.2)
break break
return holder["port"] return holder["port"]

View File

@@ -99,17 +99,13 @@ class PyProcessBase:
restore_signals=False, restore_signals=False,
**popen_kwargs, **popen_kwargs,
) )
# Route subprocess stdout/stderr into the parent's log and read the # Forward subprocess output to the log and read the startup port sentinel.
# startup port sentinel. Startup variance (cold start, antivirus) is
# absorbed here: we wait for the worker to announce its port before
# connecting.
holder = drain_and_read_port(self._process, prefix="[py_func] ") holder = drain_and_read_port(self._process, prefix="[py_func] ")
self._port = wait_for_port( self._port = wait_for_port(
self._process, holder, tm.gd("proc_start_timeout", 30) self._process, holder, tm.gd("proc_start_timeout", 30)
) )
if self._port is None: if self._port is None:
# Worker died before announcing its port: tear down fully so a # Worker died before announcing its port: reset so a later start() retries clean.
# later start() (e.g. a reused context_id engine) can retry cleanly.
self.stop() self.stop()
self.join() self.join()
return return

View File

@@ -39,8 +39,7 @@ def main():
thrd_api.dbg_out = stdio_redir.ini_stdout thrd_api.dbg_out = stdio_redir.ini_stdout
thrd_api.start() thrd_api.start()
# Announce the actual bound port on real stdout (before redirection) so the # Announce the bound port on real stdout (before redirection) so the parent connects.
# parent connects only once we are listening.
port = thrd_api.wait_bound(args.timeout) port = thrd_api.wait_bound(args.timeout)
if port is None: if port is None:
print("py_func: failed to bind a listening port", file=sys.stderr, flush=True) print("py_func: failed to bind a listening port", file=sys.stderr, flush=True)

View File

@@ -12,9 +12,7 @@ except:
from runtime.tum_except import ETUMRuntimeError from runtime.tum_except import ETUMRuntimeError
# Startup handshake: the subprocess prints this line (followed by the actual # Startup handshake: subprocess prints this + its bound port on stdout once listening.
# bound port) on stdout once its server is listening; the parent reads it and
# connects. Avoids guessing the port and connecting before the server is ready.
RPC_PORT_SENTINEL = "__TESTIUM_RPC_PORT__=" RPC_PORT_SENTINEL = "__TESTIUM_RPC_PORT__="
"""Lightweight JSON-RPC 2.0 helpers over TCP sockets. """Lightweight JSON-RPC 2.0 helpers over TCP sockets.
@@ -284,8 +282,7 @@ class JsonRpcBase(threading.Thread):
self._req_handler = req_handler self._req_handler = req_handler
self._dbg_out = dbg_out self._dbg_out = dbg_out
self._event_ready = threading.Event() self._event_ready = threading.Event()
# Event is set on success AND failure so wait_ready() never hangs; # Set on success AND failure so wait_ready() never hangs; outcome in _connected.
# _connected carries the actual outcome.
self._connected = False self._connected = False
def handle_request(self, method, params): def handle_request(self, method, params):
@@ -374,11 +371,7 @@ class JsonRpcSrv(JsonRpcBase):
try: try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
# No SO_REUSEADDR: the OS picks a fresh ephemeral port (port 0), # No SO_REUSEADDR: fresh ephemeral port; on Windows it enables hijacking.
# so there is no TIME_WAIT to override, and on Windows REUSEADDR
# would let another process hijack the port.
# Bind (port may be 0 -> OS-assigned) then publish the actual port
sock.bind((self._host, self._port)) sock.bind((self._host, self._port))
# Listens incoming connections # Listens incoming connections
@@ -406,8 +399,7 @@ class JsonRpcSrv(JsonRpcBase):
sleep(0.1) sleep(0.1)
finally: finally:
# Unblock wait_bound() even if bind/accept failed. self._bound_evt.set() # unblock wait_bound() even on failure
self._bound_evt.set()
if self._rpc is not None: if self._rpc is not None:
self._rpc.stop() self._rpc.stop()
self._rpc.join() self._rpc.join()
@@ -441,13 +433,10 @@ class JsonRpcClient(JsonRpcBase):
except Exception as e: except Exception as e:
self.print_info(f"connection failed: {e}") self.print_info(f"connection failed: {e}")
finally: finally:
# Settle wait_ready() whatever the outcome (_connected stays False self._event_ready.set() # settle wait_ready() whatever the outcome
# on failure).
self._event_ready.set()
def run_win(self): def run_win(self):
# Server is already listening (port handshake), so connect succeeds on # Server already listening (handshake); retry on refused/timeout until deadline.
# the first attempt; retry on refused/timeout until the deadline anyway.
deadline = monotonic() + self._timeout deadline = monotonic() + self._timeout
sock = None sock = None
try: try: