Skip to content

Commit 6005728

Browse files
PsUtilProcessProxy is updated (refactoring) (#212)
1 parent 44f280b commit 6005728

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Diff for: testgres/operations/remote_ops.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,25 @@
2626

2727
class PsUtilProcessProxy:
2828
def __init__(self, ssh, pid):
29+
assert isinstance(ssh, RemoteOperations)
30+
assert type(pid) == int # noqa: E721
2931
self.ssh = ssh
3032
self.pid = pid
3133

3234
def kill(self):
33-
command = "kill {}".format(self.pid)
34-
self.ssh.exec_command(command)
35+
assert isinstance(self.ssh, RemoteOperations)
36+
assert type(self.pid) == int # noqa: E721
37+
command = ["kill", str(self.pid)]
38+
self.ssh.exec_command(command, encoding=get_default_encoding())
3539

3640
def cmdline(self):
37-
command = "ps -p {} -o cmd --no-headers".format(self.pid)
38-
stdin, stdout, stderr = self.ssh.exec_command(command, verbose=True, encoding=get_default_encoding())
39-
cmdline = stdout.strip()
41+
assert isinstance(self.ssh, RemoteOperations)
42+
assert type(self.pid) == int # noqa: E721
43+
command = ["ps", "-p", str(self.pid), "-o", "cmd", "--no-headers"]
44+
output = self.ssh.exec_command(command, encoding=get_default_encoding())
45+
assert type(output) == str # noqa: E721
46+
cmdline = output.strip()
47+
# TODO: This code work wrong if command line contains quoted values. Yes?
4048
return cmdline.split()
4149

4250

0 commit comments

Comments
 (0)