lhutton1 commented on a change in pull request #10214:
URL: https://github.com/apache/tvm/pull/10214#discussion_r815032100



##########
File path: tests/python/relay/aot/aot_test_utils.py
##########
@@ -225,35 +225,43 @@ def parametrize_aot_options(test):
     )(test)
 
 
-def subprocess_log_output(cmd, cwd, logfile):
+def subprocess_check_log_output(cmd, cwd, logfile):
     """
     This method runs a process and logs the output to both a log file and 
stdout
     """
     _LOG.info("Execute (%s): %s", cwd, cmd)
     cmd_base = cmd[0] if isinstance(cmd, (list, tuple)) else cmd.split(" ", 
1)[0]
     proc = subprocess.Popen(
-        cmd, cwd=cwd, shell=True, bufsize=0, stdout=subprocess.PIPE, 
stderr=subprocess.STDOUT
+        cmd,
+        cwd=cwd,
+        shell=True,
+        bufsize=0,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.STDOUT,
+        encoding="utf-8",
     )
-    with open(logfile, "ab") as f:
-        f.write(
-            bytes(
-                "\n"
-                + "-" * 80
-                + f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: 
Execute ({cwd}): {cmd}\n"
-                + "-" * 80,
-                "utf-8",
-            )
+    with open(logfile, "a") as f:
+        msg = (
+            "\n"
+            + "-" * 80
+            + f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: 
Execute ({cwd}): {cmd}\n"
+            + "-" * 80
         )
+        f.write(msg)
         while True:
             data = proc.stdout.readline()
-            _LOG.debug("%s: %s", cmd_base, str(data, "utf-8", 
"replace").rstrip("\n"))
+            _LOG.debug("%s: %s", cmd_base, data.rstrip("\n"))
             f.write(data)
 
             # process is done if there is no data and the result is valid
             if not data:  # EOF
                 break
 
-    return proc.wait()
+    proc.wait()
+    if proc.returncode != 0:
+        raise RuntimeError(
+            f"Subprocess failed: 
{cmd}\nstdout:\n{proc.stdout}\nstderr:\n{proc.stderr}"

Review comment:
       Apologies I didn't spot this earlier, currently the runtime message is 
`<_io.TextIOWrapper name=7 encoding='utf-8'>`. I tried to manufacture a compile 
error locally and test this out, and it seems as though attempting to fix this 
with something like `proc.stdout.read()` returns just an empty string, 
presumably because the lines are already read above. Any ideas other than just 
printing the contents of the log file?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to