Terminate tee subproc if wait TimeoutExpired
import os
import sys
import subprocess
+import warnings
from io import StringIO
from contextlib import contextmanager
import wrapt
@@ -177,8 +178,17 @@ def tee_output_fd():
os.dup2(saved_stdout_fd, original_stdout_fd)
os.dup2(saved_stderr_fd, original_stderr_fd)
+ try:
tee_stdout.wait(timeout=1)
+ except subprocess.TimeoutExpired:
+ warnings.warn("tee_stdout.wait timeout. Forcibly terminating.")
+ tee_stdout.terminate()
+
+ try:
tee_stderr.wait(timeout=1)
+ except subprocess.TimeoutExpired:
+ warnings.warn("tee_stderr.wait timeout. Forcibly terminating.")
+ tee_stderr.terminate()
os.close(saved_stdout_fd)
os.close(saved_stderr_fd)
