Skip to content

Commit

Permalink
Move execute_wait into parsl.utils and remove parsl.channels remnant
Browse files Browse the repository at this point in the history
  • Loading branch information
benclifford committed Oct 24, 2024
1 parent 63f94b4 commit 4fdf781
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 45 deletions.
Empty file removed parsl/channels/__init__.py
Empty file.
Empty file removed parsl/channels/local/__init__.py
Empty file.
40 changes: 0 additions & 40 deletions parsl/channels/local/local.py

This file was deleted.

2 changes: 1 addition & 1 deletion parsl/providers/cluster_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from abc import abstractmethod
from string import Template

from parsl.channels.local.local import execute_wait
from parsl.launchers.base import Launcher
from parsl.launchers.errors import BadLauncher
from parsl.providers.base import ExecutionProvider
from parsl.providers.errors import SchedulerMissingArgs, ScriptPathError
from parsl.utils import execute_wait

logger = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions parsl/providers/local/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import time

from parsl.channels.local.local import execute_wait
from parsl.jobs.states import JobState, JobStatus
from parsl.launchers import SingleNodeLauncher
from parsl.providers.base import ExecutionProvider
Expand All @@ -11,7 +10,7 @@
ScriptPathError,
SubmitException,
)
from parsl.utils import RepresentationMixin
from parsl.utils import RepresentationMixin, execute_wait

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion parsl/tests/test_channels/test_large_output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from parsl.channels.local.local import execute_wait
from parsl.utils import execute_wait


@pytest.mark.local
Expand Down
2 changes: 1 addition & 1 deletion parsl/tests/test_channels/test_local_channel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from parsl.channels.local.local import execute_wait
from parsl.utils import execute_wait


@pytest.mark.local
Expand Down
35 changes: 35 additions & 0 deletions parsl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,38 @@ def sanitize_dns_subdomain_rfc1123(raw_string: str) -> str:
raise ValueError(f"Sanitized DNS subdomain is empty for input '{raw_string}'")

return sanitized


def execute_wait(cmd: str, walltime: Union[float, int, None] = None) -> Tuple[int, str, str]:
''' Synchronously execute a commandline string on the shell.
Args:
- cmd (string) : Commandline string to execute
- walltime (int) : walltime in seconds
Returns:
- retcode : Return code from the execution
- stdout : stdout string
- stderr : stderr string
'''
try:
logger.debug("Creating process with command '%s'", cmd)
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
preexec_fn=os.setpgrp
)
logger.debug("Created process with pid %s. Performing communicate", proc.pid)
(stdout, stderr) = proc.communicate(timeout=walltime)
retcode = proc.returncode
logger.debug("Process %s returned %s", proc.pid, proc.returncode)

except Exception:
logger.exception(f"Execution of command failed:\n{cmd}")
raise
else:
logger.debug("Execution of command in process %s completed normally", proc.pid)

return (retcode, stdout.decode("utf-8"), stderr.decode("utf-8"))

0 comments on commit 4fdf781

Please sign in to comment.