Skip to content
Open
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
20 changes: 13 additions & 7 deletions python/pyspark/sql/connect/local_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,8 @@ def _port_open(host: str, port: int, timeout: float = 0.5) -> bool:
return False


def _is_local_connect_server(pid: int) -> Optional[bool]:
"""Whether ``pid`` is still the managed Connect server recorded in discovery.

Returns ``None`` when the process cannot be inspected, so callers do not discard the
discovery information needed to retry later.
"""
def _process_command(pid: int) -> Optional[str]:
"""The command of ``pid``, an empty string if it is gone, or ``None`` if inspection fails."""
try:
result = subprocess.run(
["ps", "-ww", "-p", str(pid), "-o", "command="],
Expand All @@ -132,7 +128,17 @@ def _is_local_connect_server(pid: int) -> Optional[bool]:
)
except (OSError, subprocess.SubprocessError):
return None
return result.returncode == 0 and _SERVER_CLASS in result.stdout
return result.stdout if result.returncode == 0 else ""


def _is_local_connect_server(pid: int) -> Optional[bool]:
"""Whether ``pid`` is still the managed Connect server recorded in discovery.

Returns ``None`` when the process cannot be inspected, so callers do not discard the
discovery information needed to retry later.
"""
command = _process_command(pid)
return None if command is None else _SERVER_CLASS in command


def runtime_dir() -> str:
Expand Down
Loading