if exc_type is not None or self.alwaysprint:
self.newout.flush()
self.newerr.flush()
self.old_stdout.write(self.newout.getvalue())
self.old_stderr.write(self.newerr.getvalue())
self.old_stdout.flush()
self.old_stderr.flush()
After Change
def __exit__(self, exc_type, exc_value, traceback):
if not self.alwaysprint:
std_silent.dest_stdout.flush()
std_silent.dest_stderr.flush()
if exc_type is not None:
out = open(std_silent.dest_fname_stdout, "r").read()
err = open(std_silent.dest_fname_stderr, "r").read()
os.dup2(self.orig_out_fd, 1)
os.dup2(self.orig_err_fd, 2)
os.close(self.orig_out_fd)