ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dankil...@apache.org
Subject [5/6] incubator-ariatosca git commit: fix process
Date Wed, 19 Oct 2016 15:46:18 GMT
fix process


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/a465e6f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/a465e6f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/a465e6f1

Branch: refs/heads/pylint-tools
Commit: a465e6f1654ba42b144b94a681321c103f7d3e60
Parents: 4c566f7
Author: Dan Kilman <dankilman@gmail.com>
Authored: Wed Oct 19 16:37:32 2016 +0300
Committer: Dan Kilman <dankilman@gmail.com>
Committed: Wed Oct 19 16:53:08 2016 +0300

----------------------------------------------------------------------
 aria/tools/process.py | 59 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 46 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a465e6f1/aria/tools/process.py
----------------------------------------------------------------------
diff --git a/aria/tools/process.py b/aria/tools/process.py
index 7df0026..5a3d8a0 100644
--- a/aria/tools/process.py
+++ b/aria/tools/process.py
@@ -13,6 +13,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+"""
+Subprocess utility methods
+"""
+
 import os
 import subprocess
 from signal import SIGKILL
@@ -23,6 +27,10 @@ from aria.exceptions import ExecutorException, ProcessException
 
 
 class Process(LoggerMixin):
+    """
+    Subprocess wrapper
+    """
+
     def __init__(
             self,
             args,
@@ -32,12 +40,7 @@ class Process(LoggerMixin):
             env=None,
             **kwargs):
         """
-        Process class - subprocess wrapper
-        :param args:
-        :param stdout:
-        :param stderr:
-        :param cwd:
-        :param env:
+        Subprocess wrapper
         """
         super(Process, self).__init__(**kwargs)
         self.args = args
@@ -48,7 +51,7 @@ class Process(LoggerMixin):
         self._stderr = stderr
 
     def __repr__(self):
-        return '{cls.__name__}(args=self.args, cwd=self.cwd)'.format(
+        return '{cls.__name__}(args={self.args}, cwd={self.cwd})'.format(
             cls=self.__class__, self=self)
 
     def __getattr__(self, item):
@@ -56,25 +59,40 @@ class Process(LoggerMixin):
 
     @property
     def name(self):
+        """
+        The process name
+        """
         return self.args[0]
 
     @property
     def pid(self):
+        """
+        The process pid (if running)
+        """
         if self.is_running():
             return self.process.pid
 
     @property
     def stdout(self):
-        assert self.process, 'Need to run before calling thie method'
+        """
+        The process stdout
+        """
+        assert self.process, 'Need to run before calling this method'
         return self.process.stdout
 
     @property
     def stderr(self):
-        assert self.process, 'Need to run before calling thie method'
+        """
+        The process stderr
+        """
+        assert self.process, 'Need to run before calling this method'
         return self.process.stderr
 
     @property
     def return_code(self):
+        """
+        The process return code. Will wait for process to end if it hasn't already
+        """
         if self.process is None:
             return None
         if self.is_running():
@@ -85,6 +103,10 @@ class Process(LoggerMixin):
         return self.process.returncode
 
     def terminate(self):
+        """
+        Terminates the process by sending a SIGTERM to it. If the process did not stop after
that,
+        sends a SIGKILL with 1 second interval for a maximum of 10 times.
+        """
         if self.process is not None and self.process.poll() is None:
             self.logger.debug('terminating process {0:d} ({1})'.format(self.process.pid,
self.name))
             self.process.terminate()
@@ -96,16 +118,22 @@ class Process(LoggerMixin):
             sleep(1)
             kill_attempts += 1
 
-    def killpg(self):
+    def kill(self):
+        """
+        Kill the process by sending a SIGKILL to it
+        """
         if self.is_running():
             os.killpg(os.getpgid(self.pid), SIGKILL)
 
     def is_running(self):
+        """
+        Returns ``True`` if the process is currently running
+        """
         return self.process.poll() is None if self.process else False
 
     def wait(self):
         """
-        Block till child process finishes
+        Block until process finishes
         """
         assert self.process, 'Need to run before calling thie method'
         self.process.wait()
@@ -113,8 +141,6 @@ class Process(LoggerMixin):
     def run(self, nice=None, universal_newlines=True):
         """
         Run the child process. This call does not block.
-        :param int nice: nice on the child process run
-        :param bool universal_newlines:
         """
         self.logger.debug('Running child process: {0}'.format(' '.join(self.args)))
         self.process = subprocess.Popen(
@@ -128,6 +154,9 @@ class Process(LoggerMixin):
             universal_newlines=universal_newlines)
 
     def run_in_shell(self, nice=None, universal_newlines=True):
+        """
+        Run the child process in a shell. This call does not block.
+        """
         command = ' '.join(self.args)
         self.logger.debug('Running child process in shell: {0}'.format(command))
         self.process = subprocess.Popen(
@@ -142,6 +171,10 @@ class Process(LoggerMixin):
             universal_newlines=universal_newlines)
 
     def raise_failure(self):
+        """
+        Raise a ProcessException if the process terminated with a non zero return code. Will
wait
+        for the process to finish if it hasn't already
+        """
         if self.is_running():
             self.wait()
         if self.return_code == 0:


Mime
View raw message