[PR #1883] [Engine] serve: on Windows the engine and the image encoder start without a console window of their own #3736

Open
opened 2026-11-07 15:30:24 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1883
Author: @LeGeRyChEeSe
Created: 10/10/2026
Status: 🔄 Open

Base: main ← Head: pr/windows-no-console


📝 Commits (1)

  • 903dbce serve: on Windows the engine and the image encoder start without a console window of their own, so a server started without a console (pythonw, a service, a launcher that hides it) opens none

📊 Changes

2 files changed (+19 additions, -1 deletions)

View changed files

📝 serve/server.py (+5 -1)
📝 serve/test_server.py (+14 -0)

📄 Description

Problem and result

When the server has no console - started with pythonw, as a service, or by a launcher that hides it - Windows gives each console program it starts a new, visible console window: one for strata.exe, one for the image encoder, again at every engine restart. Their output already goes through pipes and the log, so the window is empty, and closing it by mistake ends the engine. This still happens on v0.2.2.

After the change the engine and the image encoder start without a console window of their own.

No open issue or pull request found (searched 2026-10-22: "console window", "CREATE_NO_WINDOW", "pythonw").
This pull request was closed in the 0.2.0-beta tracker reset; it is rebased on v0.2.4.1. The only change since the first version is in the test (see Validation): serve/lifeline.py now adds its own creation flag.

Approach

popen() (the #735 wrapper both children use) now sets creationflags=CREATE_NO_WINDOW on Windows when the caller gave none, as serve/mcp.py already does for MCP servers. A caller's own creationflags wins. The lifeline then adds CREATE_NEW_PROCESS_GROUP for the isolated roles, so the child gets both flags. Nothing changes on other systems, and nothing changes for a server started from a console (the child's console was the parent's, and its I/O is redirected). The job object of serve/winjob.py still ties the children to the server's lifetime.

Validation

Revision: main 8183c6b6 (v0.2.4.1) plus this one commit; the first runs were on v0.2.2 (011c9e60). Environment: Windows 11, Python 3.13, RTX 4070 SUPER.

Passed:

  • Rebased on main 8183c6b6 (v0.2.4.1): python -m unittest serve.test_server passes (353 tests, 3 skipped, Windows 11).
  • The earlier Linux CI failure was in this pull request's own test (subprocess.CREATE_NO_WINDOW read on a platform that does not define it); the last assertion now reads the flag with getattr, as the code does.
  • Live check: a pythonw.exe parent starts a console child that prints GetConsoleWindow().
    • plain subprocess.Popen: non-zero handle (a window);
    • serve.server.popen() on v0.2.2 without the change: non-zero handle (a window, observed 263400);
    • serve.server.popen() with the change: 0 (no window).
  • python -m pytest serve -q on this branch: 913 passed, 17 skipped. test_no_console_window_on_windows checks that the flag is set on Windows, absent elsewhere, and that a caller's own flags are kept. It tests the flag as a bit rather than by equality, because the lifeline adds CREATE_NEW_PROCESS_GROUP to the same field.

Failed:
none observed.

Not run:

  • Linux and macOS: the code path is guarded by os.name == "nt".
  • Windows Service and Task Scheduler launches: only the pythonw parent was tried.
  • Engine builds (CUDA, HIP, SYCL, Metal): no engine file is touched.

Limits

Windows only. A console program that is started by something other than popen() is not covered.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1883 **Author:** [@LeGeRyChEeSe](https://github.com/LeGeRyChEeSe) **Created:** 10/10/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/windows-no-console` --- ### 📝 Commits (1) - [`903dbce`](https://github.com/Niko1221/Strata/commit/903dbcec21ec832a7ab8f421bb49925e0ae26920) serve: on Windows the engine and the image encoder start without a console window of their own, so a server started without a console (pythonw, a service, a launcher that hides it) opens none ### 📊 Changes **2 files changed** (+19 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+5 -1) 📝 `serve/test_server.py` (+14 -0) </details> ### 📄 Description ## Problem and result When the server has no console - started with `pythonw`, as a service, or by a launcher that hides it - Windows gives each console program it starts a **new, visible** console window: one for `strata.exe`, one for the image encoder, again at every engine restart. Their output already goes through pipes and the log, so the window is empty, and closing it by mistake ends the engine. This still happens on v0.2.2. After the change the engine and the image encoder start without a console window of their own. ## Related discussion No open issue or pull request found (searched 2026-10-22: "console window", "CREATE_NO_WINDOW", "pythonw"). This pull request was closed in the 0.2.0-beta tracker reset; it is rebased on v0.2.4.1. The only change since the first version is in the test (see Validation): `serve/lifeline.py` now adds its own creation flag. ## Approach `popen()` (the #735 wrapper both children use) now sets `creationflags=CREATE_NO_WINDOW` on Windows when the caller gave none, as `serve/mcp.py` already does for MCP servers. A caller's own `creationflags` wins. The lifeline then adds `CREATE_NEW_PROCESS_GROUP` for the isolated roles, so the child gets both flags. Nothing changes on other systems, and nothing changes for a server started from a console (the child's console was the parent's, and its I/O is redirected). The job object of `serve/winjob.py` still ties the children to the server's lifetime. ## Validation Revision: `main` `8183c6b6` (v0.2.4.1) plus this one commit; the first runs were on v0.2.2 (`011c9e60`). Environment: Windows 11, Python 3.13, RTX 4070 SUPER. **Passed:** - Rebased on `main` `8183c6b6` (v0.2.4.1): `python -m unittest serve.test_server` passes (353 tests, 3 skipped, Windows 11). - The earlier Linux CI failure was in this pull request's own test (`subprocess.CREATE_NO_WINDOW` read on a platform that does not define it); the last assertion now reads the flag with `getattr`, as the code does. - Live check: a `pythonw.exe` parent starts a console child that prints `GetConsoleWindow()`. - plain `subprocess.Popen`: non-zero handle (a window); - `serve.server.popen()` on v0.2.2 without the change: non-zero handle (a window, observed `263400`); - `serve.server.popen()` with the change: `0` (no window). - `python -m pytest serve -q` on this branch: 913 passed, 17 skipped. `test_no_console_window_on_windows` checks that the flag is set on Windows, absent elsewhere, and that a caller's own flags are kept. It tests the flag as a bit rather than by equality, because the lifeline adds `CREATE_NEW_PROCESS_GROUP` to the same field. **Failed:** none observed. **Not run:** - Linux and macOS: the code path is guarded by `os.name == "nt"`. - Windows Service and Task Scheduler launches: only the `pythonw` parent was tried. - Engine builds (CUDA, HIP, SYCL, Metal): no engine file is touched. ## Limits Windows only. A console program that is started by something other than `popen()` is not covered. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3736
No description provided.