summaryrefslogtreecommitdiff
path: root/buildscripts/resmokelib/core/process.py
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/resmokelib/core/process.py')
-rw-r--r--buildscripts/resmokelib/core/process.py39
1 files changed, 14 insertions, 25 deletions
diff --git a/buildscripts/resmokelib/core/process.py b/buildscripts/resmokelib/core/process.py
index 42f9454bd91..4b94b2dd016 100644
--- a/buildscripts/resmokelib/core/process.py
+++ b/buildscripts/resmokelib/core/process.py
@@ -1,5 +1,4 @@
-"""
-A more reliable way to create and destroy processes.
+"""A more reliable way to create and destroy processes.
Uses job objects when running on Windows to ensure that all created
processes are terminated.
@@ -30,12 +29,12 @@ if os.name == "posix" and sys.version_info[0] == 2:
warnings.warn(("Falling back to using the subprocess module because subprocess32 isn't"
" available. When using the subprocess module, a child process may trigger"
" an invalid free(). See SERVER-22219 for more details."), RuntimeWarning)
- import subprocess
+ import subprocess # type: ignore
else:
import subprocess
-from . import pipe
-from .. import utils
+from . import pipe # pylint: disable=wrong-import-position
+from .. import utils # pylint: disable=wrong-import-position
# Attempt to avoid race conditions (e.g. hangs caused by a file descriptor being left open) when
# starting subprocesses concurrently from multiple threads by guarding calls to subprocess.Popen()
@@ -87,15 +86,12 @@ if sys.platform == "win32":
class Process(object):
- """
- Wrapper around subprocess.Popen class.
- """
+ """Wrapper around subprocess.Popen class."""
+
+ # pylint: disable=protected-access
def __init__(self, logger, args, env=None, env_vars=None):
- """
- Initializes the process with the specified logger, arguments,
- and environment.
- """
+ """Initialize the process with the specified logger, arguments, and environment."""
# Ensure that executable files that don't already have an
# extension on Windows have a ".exe" extension.
@@ -115,10 +111,7 @@ class Process(object):
self._stderr_pipe = None
def start(self):
- """
- Starts the process and the logger pipes for its stdout and
- stderr.
- """
+ """Start the process and the logger pipes for its stdout and stderr."""
creation_flags = 0
if sys.platform == "win32" and _JOB_OBJECT is not None:
@@ -158,12 +151,12 @@ class Process(object):
if return_code == win32con.STILL_ACTIVE:
raise
- def stop(self, kill=False):
+ def stop(self, kill=False): # pylint: disable=too-many-branches
"""Terminate the process."""
if sys.platform == "win32":
# Attempt to cleanly shutdown mongod.
- if not kill and len(self.args) > 0 and self.args[0].find("mongod") != -1:
+ if not kill and self.args and self.args[0].find("mongod") != -1:
mongo_signal_handle = None
try:
mongo_signal_handle = win32event.OpenEvent(
@@ -218,13 +211,11 @@ class Process(object):
raise
def poll(self):
+ """Poll."""
return self._process.poll()
def wait(self):
- """
- Waits until the process has terminated and all output has been
- consumed by the logger pipes.
- """
+ """Wait until process has terminated and all output has been consumed by the logger pipes."""
return_code = self._process.wait()
@@ -236,9 +227,7 @@ class Process(object):
return return_code
def as_command(self):
- """
- Returns an equivalent command line invocation of the process.
- """
+ """Return an equivalent command line invocation of the process."""
default_env = os.environ
env_diff = self.env.copy()