fix(browser): server shutdown and its tests on Windows, Python < 3.13 and CI
Three CI failures on ed809f7:
- Windows: server.py exited 1 on stdin EOF because create_app works with
the temp root as its cwd, and Windows cannot remove a process's cwd.
main() now restores the original cwd before the root is removed.
- Python 3.10 to 3.12: the lifetime test's cleanup called communicate()
after closing stdin, which flushes the closed pipe (ValueError); 3.13
tolerates it. It now waits and closes the pipes itself, and the exit
assertion shows the server's stderr. Under 3.12: errors=2 before, OK
after.
- Tooling (CI container): the SIGKILLed-worker tests treated an exited
server as alive, because the container's PID 1 does not reap orphans
and kill(pid, 0) succeeds on a zombie. Reproduced locally with docker
without --init (2 failed); a zombie now counts as exited (2 passed).
This commit is contained in:
@@ -583,8 +583,13 @@ def main(argv: list[str] | None = None) -> None:
|
||||
loop = asyncio.new_event_loop()
|
||||
if args.exit_on_stdin_eof:
|
||||
exit_when_stdin_closes(loop)
|
||||
original_cwd = os.getcwd()
|
||||
with tempfile.TemporaryDirectory(prefix="pm-browser-") as directory:
|
||||
web.run_app(create_app(Path(directory).resolve()), sock=listener, loop=loop)
|
||||
try:
|
||||
web.run_app(create_app(Path(directory).resolve()), sock=listener, loop=loop)
|
||||
finally:
|
||||
# create_app works inside the root; Windows cannot remove a process's cwd.
|
||||
os.chdir(original_cwd)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user