Skip to content

Commit 0caae23

Browse files
committed
refactor: do not fail when kill process by pid
Do not fail if exception is raised when kill process by pid. This pid might be already killed by something else.
1 parent ae28d9a commit 0caae23

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

core/utils/gradle.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# noinspection SpellCheckingInspection
21
"""
3-
# noinspection SpellCheckingInspection
42
A wrapper around Gradle.
53
"""
64

@@ -12,7 +10,6 @@
1210
from core.utils.process import Run, Process
1311

1412

15-
# noinspection SpellCheckingInspection
1613
class Gradle(object):
1714
@staticmethod
1815
def kill():

core/utils/image_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_pixels_by_color(image_path, color, rdb_tolerance=25):
6868
Get count of pixels of specific color.
6969
:param image_path: Image path.
7070
:param color: Color as numpy array. Example: numpy.array([255, 217, 141])
71-
:param rdb_tolerance If diff or rgb values is less then this count pixels will be counted as equal.
71+
:param rdb_tolerance If diff of sums of rgb values is less then specified count pixels will be counted as equal.
7272
:return: Count of pixels.
7373
"""
7474
img = ImageUtils.read_image(image_path=image_path)

core/utils/java.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
class Java(object):
99
@staticmethod
1010
def version():
11+
"""
12+
Java version.
13+
:rtype: float
14+
"""
1115
result = Run.command('java -version')
1216
return Version.get(result.output.split('"')[1])

core/utils/process.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def command(cmd, cwd=Settings.TEST_RUN_HOME, wait=True, register_for_cleanup=Tru
5454
output = (str(out) + os.linesep + str(err)).rstrip()
5555
complete = True
5656
end = time.time()
57-
duration = end - start;
57+
duration = end - start
5858
else:
5959
process = Popen(cmd, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True, cwd=cwd)
6060

@@ -78,7 +78,9 @@ def command(cmd, cwd=Settings.TEST_RUN_HOME, wait=True, register_for_cleanup=Tru
7878
class Process(object):
7979
@staticmethod
8080
def is_running(proc_name):
81-
"""Check if process is running"""
81+
"""
82+
Check if process is running.
83+
"""
8284
result = False
8385
for proc in psutil.process_iter():
8486
if proc_name in str(proc):
@@ -88,7 +90,9 @@ def is_running(proc_name):
8890

8991
@staticmethod
9092
def is_running_by_commandline(commandline):
91-
"""Check if process with specified commandline is running"""
93+
"""
94+
Check if process with specified commandline is running.
95+
"""
9296
proc = Process.get_proc_by_commandline(commandline=commandline)
9397
if proc is not None:
9498
return True
@@ -116,7 +120,8 @@ def get_proc_by_commandline(commandline):
116120

117121
@staticmethod
118122
def wait_until_running(proc_name, timeout=60):
119-
"""Wait until process is running
123+
"""
124+
Wait until process is running
120125
:param proc_name: Process name.
121126
:param timeout: Timeout in seconds.
122127
:return: True if running, false if not running.
@@ -177,8 +182,11 @@ def kill_by_commandline(cmdline):
177182

178183
@staticmethod
179184
def kill_pid(pid):
180-
p = psutil.Process(pid)
181-
p.terminate()
185+
try:
186+
p = psutil.Process(pid)
187+
p.terminate()
188+
except Exception:
189+
pass
182190

183191
@staticmethod
184192
def kill_by_handle(file_path):

core/utils/wait.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
class Wait(object):
55
@staticmethod
66
def until(condition, timeout=60, period=1, *args, **kwargs):
7+
"""
8+
Wait until condition is satisfied.
9+
:rtype: bool
10+
:returns: True if condition is satisfied before timeout, otherwise False.
11+
"""
712
end_time = time.time() + timeout
813
while time.time() < end_time:
914
if condition(*args, **kwargs):

core/utils/xcode.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ def get_version():
1919
Get Xcode version
2020
:return: Version as int.
2121
"""
22-
# noinspection SpellCheckingInspection
2322
result = Run.command(cmd='xcodebuild -version').output.splitlines()[0].replace(' ', '').replace('Xcode', '')
2423
return Version.get(result)

0 commit comments

Comments
 (0)