Skip to content
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

Resolve problems on Windows running the sub processes when in editable mode #18379

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion chia/_tests/cmds/test_daemon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
from pathlib import Path
from typing import Any, Dict, Optional

Expand All @@ -9,7 +10,7 @@
from pytest_mock import MockerFixture

from chia.cmds.chia import cli
from chia.cmds.start_funcs import create_start_daemon_connection
from chia.cmds.start_funcs import create_start_daemon_connection, launch_start_daemon


@pytest.mark.anyio
Expand Down Expand Up @@ -52,6 +53,20 @@ def get_current_passphrase() -> Optional[str]:
assert not captured.out.endswith("Skipping to unlock keyring\n")


@pytest.mark.anyio
def test_launch_start_daemon(tmp_path: Path) -> None:
sys.argv[0] = "not-exist"
with pytest.raises(FileNotFoundError):
launch_start_daemon(tmp_path)

helper: Path = Path(sys.executable)
sys.argv[0] = str(helper.parent) + "/chia"
process = launch_start_daemon(tmp_path)
assert process is not None
process.kill()
process.wait()


def test_start_daemon(tmp_path: Path, empty_keyring: Any, mocker: MockerFixture) -> None:
class DummyDaemon:
@staticmethod
Expand Down
8 changes: 7 additions & 1 deletion chia/cmds/start_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import os
import shutil
import subprocess
import sys
from concurrent.futures import ThreadPoolExecutor
Expand All @@ -21,8 +22,13 @@ def launch_start_daemon(root_path: Path) -> subprocess.Popen:
if sys.platform == "win32":
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.CREATE_NO_WINDOW

path_helper: Path = Path(sys.argv[0])
cmd_to_execute = shutil.which(cmd=path_helper.name, path=path_helper.parent)
if cmd_to_execute is None:
cmd_to_execute = sys.argv[0]

process = subprocess.Popen(
[sys.argv[0], "run_daemon", "--wait-for-unlock"],
[cmd_to_execute, "run_daemon", "--wait-for-unlock"],
encoding="utf-8",
stdout=subprocess.PIPE,
creationflags=creationflags,
Expand Down
4 changes: 3 additions & 1 deletion chia/daemon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import logging
import os
import shutil
import signal
import ssl
import subprocess
Expand Down Expand Up @@ -112,7 +113,8 @@ def executable_for_service(service_name: str) -> str:
application_path = os.path.dirname(__file__)

def executable_for_service(service_name: str) -> str:
return service_name
cmd_to_exec = shutil.which(service_name)
return cmd_to_exec if cmd_to_exec is not None else service_name


async def ping() -> Dict[str, Any]:
Expand Down
Loading