Skip to content

Commit

Permalink
remove redirectIO (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
akleb authored Feb 21, 2022
1 parent 32927ea commit c5861ec
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
5 changes: 2 additions & 3 deletions multipoint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
__version__ = "1.3.2"
__version__ = "1.4.0"


from .multiPointSparse import multiPointSparse
from .utils import createGroups
from .utils import redirectIO

__all__ = ["multiPointSparse", "createGroups", "redirectIO"]
__all__ = ["multiPointSparse", "createGroups"]
30 changes: 0 additions & 30 deletions multipoint/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os
import sys
import io
import copy
from mpi4py import MPI
import numpy as np
Expand Down Expand Up @@ -92,30 +89,3 @@ def createGroups(sizes, comm):
flags[member_key] = True

return new_comm, flags


def redirectIO(f):
"""
Redirect stdout/stderr to the given file handle.
Based on: http://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/.
Written by Bret Naylor
"""
original_stdout_fd = sys.stdout.fileno()
original_stderr_fd = sys.stderr.fileno()

sys.stdout.flush()
sys.stderr.flush()

# Flush and close sys.stdout/err - also closes the file descriptors (fd)
sys.stdout.close()
sys.stderr.close()

# Make original_stdout_fd point to the same file as to_fd
os.dup2(f.fileno(), original_stdout_fd)
os.dup2(f.fileno(), original_stderr_fd)

# Create a new sys.stdout that points to the redirected fd

# For Python 3.x
sys.stdout = io.TextIOWrapper(os.fdopen(original_stdout_fd, "wb"))
sys.stderr = io.TextIOWrapper(os.fdopen(original_stderr_fd, "wb"))

0 comments on commit c5861ec

Please sign in to comment.