Skip to content

Commit

Permalink
Make python-exec replace the existing process
Browse files Browse the repository at this point in the history
The `python-exec` CLI command now uses `execvpe` to replace the existing
process rather than launch an additional subprocess. This reduces some
process complexity and ensures that signals make it to their intended
destination.
  • Loading branch information
rjmello committed Aug 1, 2024
1 parent dc89e10 commit fd87bbd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions compute_endpoint/globus_compute_endpoint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import gzip
import json
import logging
import os
import pathlib
import re
import shutil
import subprocess
import sys
import textwrap
import uuid
Expand Down Expand Up @@ -924,7 +924,7 @@ def run_python_executable(ctx: click.Context, module: str):
E.g., globus-compute-endpoint python-exec path.to.module --ahoy matey
"""
subprocess.run([sys.executable, "-m", module] + ctx.args)
os.execvpe(sys.executable, [sys.executable, "-m", module] + ctx.args, os.environ)


def create_or_choose_auth_project(ac: AuthClient) -> str:
Expand Down
8 changes: 5 additions & 3 deletions compute_endpoint/tests/unit/test_cli_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,12 @@ def run_cmd():


def test_python_exec(mocker: MockFixture, run_line: t.Callable):
mock_subprocess_run = mocker.patch("subprocess.run")
mock_execvpe = mocker.patch("os.execvpe")
run_line("python-exec path.to.module arg --option val")
mock_subprocess_run.assert_called_with(
[sys.executable, "-m", "path.to.module", "arg", "--option", "val"]
mock_execvpe.assert_called_with(
sys.executable,
[sys.executable, "-m", "path.to.module", "arg", "--option", "val"],
os.environ,
)


Expand Down

0 comments on commit fd87bbd

Please sign in to comment.