Repository navigation
launch --background: honor --log-file and COMFY_CLI_BACKGROUND_LOG for the log path #1059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -411,6 +411,7 @@ def launch( | |||||
| background: bool = False, | ||||||
| extra: list[str] | None = None, | ||||||
| frontend_pr: str | None = None, | ||||||
| log_file: str | None = None, | ||||||
| ): | ||||||
| resolved_workspace = workspace_manager.workspace_path | ||||||
|
|
||||||
|
|
@@ -451,12 +452,12 @@ def launch( | |||||
| extra = (extra or []) + manager_flags | ||||||
|
|
||||||
| if background: | ||||||
| background_launch(extra, frontend_pr) | ||||||
| background_launch(extra, frontend_pr, log_file=log_file) | ||||||
| else: | ||||||
| launch_comfyui(extra, frontend_pr, python=python) | ||||||
|
|
||||||
|
|
||||||
| def background_launch(extra, frontend_pr=None): | ||||||
| def background_launch(extra, frontend_pr=None, log_file=None): | ||||||
| renderer = get_renderer() | ||||||
| config_background = ConfigManager().background | ||||||
| if config_background is not None and utils.is_running(config_background[2]): | ||||||
|
|
@@ -538,7 +539,7 @@ def background_launch(extra, frontend_pr=None): | |||||
|
|
||||||
| cmd.extend(extra) | ||||||
|
|
||||||
| log = asyncio.run(launch_and_monitor(cmd, listen, port)) | ||||||
| log = asyncio.run(launch_and_monitor(cmd, listen, port, log_file=log_file)) | ||||||
|
|
||||||
| # Reaching here means the monitor returned without seeing the success line | ||||||
| # (the success path emits its envelope and _hard_exit(0)s inside the monitor). | ||||||
|
|
@@ -574,15 +575,25 @@ def background_launch(extra, frontend_pr=None): | |||||
| _hard_exit(1) | ||||||
|
|
||||||
|
|
||||||
| def background_log_path(port, workspace: str | None = None) -> str: | ||||||
| def background_log_path(port, workspace: str | None = None, override: str | None = None) -> str: | ||||||
| """Path to the persisted background ComfyUI log for ``port``. | ||||||
|
|
||||||
| ``<workspace>/user/comfyui_<port>.log`` — ``<port>`` disambiguates multiple | ||||||
| installs that share one comfy-cli config. Truncated on each background launch | ||||||
| (a fresh run starts a fresh log). ``workspace`` defaults to the current | ||||||
| working directory, which ``launch`` has already ``chdir``'d to the resolved | ||||||
| workspace by the time the background monitor runs. | ||||||
|
|
||||||
| ``override`` (the ``--log-file`` flag, or the ``COMFY_CLI_BACKGROUND_LOG`` | ||||||
| env var a supervising process can set for its own children) replaces the | ||||||
| path verbatim: a supervisor that names the file owns the naming too, so the | ||||||
| ``<port>`` suffix logic does not apply. The chosen path is what gets recorded | ||||||
| under ``CONFIG_KEY_BACKGROUND_LOG``, so ``comfy logs`` and ``comfy stop`` | ||||||
| resolve it like any other background log. | ||||||
| """ | ||||||
| override = override or os.environ.get("COMFY_CLI_BACKGROUND_LOG") | ||||||
| if override: | ||||||
| return os.path.abspath(override) | ||||||
| if workspace is None: | ||||||
| workspace = os.path.abspath(os.getcwd()) | ||||||
| return os.path.join(workspace, "user", f"comfyui_{port}.log") | ||||||
|
|
@@ -604,7 +615,7 @@ def _open_log_for_write(log_path: str): | |||||
| return os.fdopen(fd, "w", encoding="utf-8") | ||||||
|
|
||||||
|
|
||||||
| async def launch_and_monitor(cmd, listen, port): | ||||||
| async def launch_and_monitor(cmd, listen, port, log_file=None): | ||||||
| """ | ||||||
| Monitor the process during the background launch. | ||||||
|
|
||||||
|
|
@@ -628,7 +639,7 @@ async def launch_and_monitor(cmd, listen, port): | |||||
| # promptly instead of sitting in a block buffer (stdout is a file, not a tty). | ||||||
| env["PYTHONUNBUFFERED"] = "1" | ||||||
|
|
||||||
| log_path = background_log_path(port) | ||||||
| log_path = background_log_path(port, override=log_file) | ||||||
|
|
||||||
| # Truncate-on-launch: each background launch starts a fresh log. The child | ||||||
| # inherits its own dup of this fd, so writes continue after we (the monitor) | ||||||
|
|
@@ -654,8 +665,10 @@ async def launch_and_monitor(cmd, listen, port): | |||||
| # when startup fails before the success marker below (where the running | ||||||
| # background info is recorded). A fresh ConfigManager re-reads this on the | ||||||
| # success path. | ||||||
| # %% escapes ConfigParser interpolation: a --log-file like | ||||||
| # /tmp/run%20.log would otherwise raise on every later read of the key. | ||||||
| cfg = ConfigManager() | ||||||
| cfg.config["DEFAULT"][constants.CONFIG_KEY_BACKGROUND_LOG] = log_path | ||||||
| cfg.config["DEFAULT"][constants.CONFIG_KEY_BACKGROUND_LOG] = log_path.replace("%", "%%") | ||||||
| cfg.write_config() | ||||||
|
|
||||||
| try: | ||||||
|
|
@@ -692,7 +705,7 @@ def _handle(line): | |||||
| # we add the running background info now that startup succeeded. | ||||||
| cfg = ConfigManager() | ||||||
| cfg.config["DEFAULT"][constants.CONFIG_KEY_BACKGROUND] = f"{(listen, port, process.pid)}" | ||||||
| cfg.config["DEFAULT"][constants.CONFIG_KEY_BACKGROUND_LOG] = log_path | ||||||
| cfg.config["DEFAULT"][constants.CONFIG_KEY_BACKGROUND_LOG] = log_path.replace("%", "%%") | ||||||
| cfg.write_config() | ||||||
|
|
||||||
| _emit_launch_success(listen, port, process.pid) | ||||||
|
|
@@ -856,7 +869,7 @@ def candidate_log_paths(port: int | None = None) -> list[tuple[str, str]]: | |||||
| ] | ||||||
|
|
||||||
| cfg = ConfigManager() | ||||||
| recorded = cfg.get(constants.CONFIG_KEY_BACKGROUND_LOG) | ||||||
| recorded = (cfg.get(constants.CONFIG_KEY_BACKGROUND_LOG) or "").replace("%%", "%") or None | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the second percent unescaping.
--- "a/comfy_cli/command/launch.py"
+++ "b/comfy_cli/command/launch.py"
@@ -869,7 +869,7 @@
]
cfg = ConfigManager()
- recorded = (cfg.get(constants.CONFIG_KEY_BACKGROUND_LOG) or "").replace("%%", "%") or None
+ recorded = cfg.get(constants.CONFIG_KEY_BACKGROUND_LOG) or None
if not workspace:
# Nothing local to prefer it over, and nothing else to check.Committable suggestion
|
||||||
|
|
||||||
| if not workspace: | ||||||
| # Nothing local to prefer it over, and nothing else to check. | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.