Skip to content

Instantly share code, notes, and snippets.

View nocollier's full-sized avatar

Nathan Collier nocollier

  • Oak Ridge National Laboratory
  • Tennessee
View GitHub Profile
@JohnCEarls
JohnCEarls / mpi4py_logger.py
Created December 29, 2013 17:45
Creates a file handler that uses a shared mpi file for logging using the base python logging module. Based on Lisandro's post at https://groups.google.com/forum/#!topic/mpi4py/SaNzc8bdj6U in the mpi4py newsgroup.
import logging
from mpi4py import MPI
class MPIFileHandler(logging.FileHandler):
def __init__(self,filename, mode=MPI.MODE_WRONLY|MPI.MODE_CREATE|MPI.MODE_APPEND , encoding=None, delay=0, comm=MPI.COMM_WORLD ):
encoding = None
self.baseFilename = os.path.abspath(filename)
self.mode = mode
self.encoding = encoding
self.comm = comm