Skip to content

Commit

Permalink
Make util.run py3 compatible. (kubeflow#281)
Browse files Browse the repository at this point in the history
* It looks like on python3 util.run keeps polling for the end of stdout
  becase we don't treat the final line as a byte string e.g b''.

* Need to decode some strings in python3.
  • Loading branch information
jlewi authored and k8s-ci-robot committed Jan 16, 2019
1 parent ea5294f commit 000a1ce
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions py/kubeflow/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import re
import six
import subprocess
import time
import urllib
Expand Down Expand Up @@ -57,16 +58,25 @@ def run(command,
output = []
while process.poll() is None:
process.stdout.flush()
for line in iter(process.stdout.readline, ''):
output.append(line.strip())
logging.info(line.strip())
for line in iter(process.stdout.readline, b''):
if six.PY2:
line = line.strip()
else:
line = line.decode().strip()

output.append(line)
logging.info(line)

time.sleep(polling_interval.total_seconds())

process.stdout.flush()
for line in iter(process.stdout.readline, b''):
output.append(line.strip())
logging.info(line.strip())
if six.PY2:
line = line.strip()
else:
line = line.decode().strip()
output.append(line)
logging.info(line)

if process.returncode != 0:
raise subprocess.CalledProcessError(
Expand Down

0 comments on commit 000a1ce

Please sign in to comment.