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

[WIP] Validate if Runner process exists #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions mlcube/mlcube/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
import typing as t

import psutil

from mlcube.errors import (ConfigurationError, IllegalParameterTypeError, IllegalParameterValueError)

from omegaconf import DictConfig
Expand Down Expand Up @@ -102,3 +104,17 @@ def validate_type(obj, expected_type) -> None:
"""
if not isinstance(obj, expected_type):
raise TypeError(f"Actual object type ({type(obj)}) != expected type ({expected_type}).")


@staticmethod
def validate_running_process(processName):
"""Check if there is any running process that contains the given name processName"""
#Iterate over the all the running process
for proc in psutil.process_iter():
try:
# Check if process name contains the given name string.
if processName.lower() in proc.name().lower():
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
3 changes: 2 additions & 1 deletion mlcube/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ coloredlogs==14.0
cookiecutter==1.7.2
docker==4.3.1
PyYAML>=5.4
omegaconf==2.1.0
omegaconf==2.1.0
psutil==5.9.1
5 changes: 5 additions & 0 deletions runners/mlcube_docker/mlcube_docker/docker_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ def configure(self) -> None:

def run(self) -> None:
""" Run a cube. """
# Validate Runner process is available
if not Validate.validate_running_process(self.mlcube.runner.runner):
raise ProcessLookupError("Docker process is not running!")


docker: t.Text = self.mlcube.runner.docker
image: t.Text = self.mlcube.runner.image

Expand Down