Source code for uhammer
# encoding: utf-8
import sys
import pkg_resources
from ._parallel import runs_with_mpi as _runs_with_mpi
from .lnprob_adapters import *  # noqa
from .parameters import Parameters  # noqa
from .persisting import load_samples  # noqa
from .persisting import persist_every_n_iterations  # noqa
from .persisting import persist_final  # noqa
from .persisting import persist_on_error  # noqa
from .sampler import *  # noqa
[docs]class Unbuffered(object):
    def __init__(self, stream):
        self.stream = stream
[docs]    def write(self, data):
        self.stream.write(data)
        self.stream.flush() 
[docs]    def writelines(self, datas):
        self.stream.writelines(datas)
        self.stream.flush() 
    def __getattr__(self, attr):
        return getattr(self.stream, attr) 
# unbuffered IO is usefull not to miss output or stack traces when jobs shut
# down:
sys.stdout = Unbuffered(sys.stdout)
sys.stderr = Unbuffered(sys.stderr)
if _runs_with_mpi():
    def handler(type_, value, tb):
        import traceback
        from mpi4py import MPI
        traceback.print_tb(tb, file=sys.stdout)
        sys.stdout.flush()
        MPI.COMM_WORLD.Abort(1)
    sys.excepthook = handler
__version__ = pkg_resources.require(__package__)[0].version