Tools: Attempt to make perf.py work with Py3

This commit is contained in:
Vicki Pfau 2019-06-07 12:46:38 -07:00
parent a63c46cd35
commit 26fa36f9e5
1 changed files with 6 additions and 3 deletions

View File

@ -96,12 +96,15 @@ class PerfServer(object):
subprocess.check_call(server_command) subprocess.check_call(server_command)
time.sleep(4) time.sleep(4)
self.socket = socket.create_connection(self.address, timeout=1000) self.socket = socket.create_connection(self.address, timeout=1000)
self.reader = csv.DictReader(self.socket.makefile()) kwargs = {}
if sys.version_info[0] >= 3:
kwargs["encoding"] = "utf-8"
self.reader = csv.DictReader(self.socket.makefile(**kwargs))
def run(self, test): def run(self, test):
if not self.socket: if not self.socket:
self._start(test) self._start(test)
self.socket.send(os.path.join("/perfroms", test.rom)) self.socket.send(os.path.join("/perfroms", test.rom).encode("utf-8"))
self.results.append(next(self.reader)) self.results.append(next(self.reader))
self.iterations -= 1 self.iterations -= 1
if self.iterations == 0: if self.iterations == 0:
@ -109,7 +112,7 @@ class PerfServer(object):
self.iterations = self.ITERATIONS_PER_INSTANCE self.iterations = self.ITERATIONS_PER_INSTANCE
def finish(self): def finish(self):
self.socket.send("\n"); self.socket.send(b"\n");
self.reader = None self.reader = None
self.socket.close() self.socket.close()
time.sleep(5) time.sleep(5)