Skip to content

Commit d7334a4

Browse files
committed
decode bytes returned from subprocess in attach helper
1 parent db8d770 commit d7334a4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

scripts/attach_helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def jobid_to_hostname_pid(rm, jobid, remoteshell):
4444
rm = rm.lower()
4545
if rm == 'slurm':
4646
proc = subprocess.Popen(["squeue", "-j", jobid, "-tr", "-o", '%B"'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
47-
ret = proc.stdout.read()
47+
ret = proc.stdout.read().decode().replace('"', '')
4848
lines = ret.splitlines()
4949
if not lines or lines[0].find("EXEC_HOST") != 0 or len(lines) < 2:
5050
return None, None, []
@@ -53,15 +53,15 @@ def jobid_to_hostname_pid(rm, jobid, remoteshell):
5353
remotehosts = [lines[1]]
5454
if rm == 'lsf':
5555
proc = subprocess.Popen(["bjobs", "-noheader", "-X", "-o", "exec_host", jobid], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
56-
ret = proc.stdout.read()
56+
ret = proc.stdout.read().decode().replace('"', '')
5757
lines = ret.splitlines()
5858
if not lines or lines[0].find("not found") != -1 or lines[0].find("-") != -1:
5959
return None, None, []
6060
tokens = lines[0].split('*')
6161
remotehosts = [tokens[1][:tokens[1].find(':')], tokens[2][:tokens[1].find(':')]]
6262
if rm == 'alps':
6363
proc = subprocess.Popen(["qstat", "-f", jobid], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
64-
ret = proc.stdout.read()
64+
ret = proc.stdout.read().decode().replace('"', '')
6565
lines = ret.splitlines()
6666
for line in lines:
6767
if line.find("login_node_id") != -1:
@@ -74,7 +74,7 @@ def jobid_to_hostname_pid(rm, jobid, remoteshell):
7474
domain_name = socket.getfqdn().strip(socket.gethostname())
7575
remotehost = remotehost[:remotehost.find('.localdomain')]
7676
proc = subprocess.Popen([remoteshell, remotehost, "ps", "x"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
77-
ret = proc.stdout.read()
77+
ret = proc.stdout.read().decode()
7878
if lines == []:
7979
continue
8080
lines = ret.splitlines()

0 commit comments

Comments
 (0)