Skip to content

Commit

Permalink
Enable fd 1,2,3 in child.py (#1013)
Browse files Browse the repository at this point in the history
Co-authored-by: yuxuan-ms <[email protected]>
  • Loading branch information
yuxuan-ms and yuxuan-ms authored Nov 1, 2023
1 parent a8b04fd commit 1fa7098
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions testplan/runners/pools/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,22 @@ def _setup_logfiles(self):
if not os.path.exists(self.runpath):
os.makedirs(self.runpath)

stderr_file = os.path.join(
self.runpath, f"{self._metadata['index']}_stderr"
)
log_file = os.path.join(
stdout_file = os.path.join(
self.runpath, f"{self._metadata['index']}_stdout"
)
self.logger.info(
"stdout file = %(file)s (log level = %(lvl)s)",
{"file": log_file, "lvl": self.logger.level},
stderr_file = os.path.join(
self.runpath, f"{self._metadata['index']}_stderr"
)
log_file = os.path.join(self.runpath, f"{self._metadata['index']}_log")
self.logger.info("stdout file = %s", stdout_file)
self.logger.info("stderr file = %s", stderr_file)
self.logger.info(
"Closing stdin, stdout and stderr file descriptors..."
"log file = %(file)s (log level = %(lvl)s)",
{"file": log_file, "lvl": self.logger.level},
)

# This closes stdin, stdout and stderr for this process.
for fdesc in range(3):
os.close(fdesc)
mode = "w" if platform.python_version().startswith("3") else "wb"

sys.stderr = open(stderr_file, mode)
sys.stderr = open(stderr_file, "w")
sys.stdout = open(stdout_file, "w")
fhandler = logging.FileHandler(log_file, encoding="utf-8")

formatter = logging.Formatter(LOGFILE_FORMAT)
Expand Down

0 comments on commit 1fa7098

Please sign in to comment.