#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: sesscreate.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>

import tensorflow as tf

__all__ = ['NewSessionCreator', 'ReuseSessionCreator', 'SessionCreatorAdapter']


class NewSessionCreator(tf.train.SessionCreator):
    def __init__(self, target='', graph=None, config=None):
        """
        Args:
            target, graph, config: same as :meth:`Session.__init__()`.
        """
        self.target = target
        self.config = config
        self.graph = graph

    def create_session(self):
        return tf.Session(target=self.target, graph=self.graph, config=self.config)


class ReuseSessionCreator(tf.train.SessionCreator):
    def __init__(self, sess):
        """
        Args:
            sess (tf.Session): the session to reuse
        """
        self.sess = sess

    def create_session(self):
        return self.sess


class SessionCreatorAdapter(tf.train.SessionCreator):
    def __init__(self, session_creator, func):
        """
        Args:
            session_creator (tf.train.SessionCreator): a session creator
            func (tf.Session -> tf.Session): takes a session created by
            ``session_creator``, and return a new session to be returned by ``self.create_session``
        """
        self._creator = session_creator
        self._func = func

    def create_session(self):
        sess = self._creator.create_session()
        return self._func(sess)

@@ -126,16 +126,60 @@
 ow as tf
+%0Afrom .common import get_default_sess_config
 %0A%0A__all_
@@ -473,40 +473,188 @@
     
-%22%22%22%0A        self.target = target
+    config: defaults to :func:%60tfutils.get_default_sess_config()%60%0A        %22%22%22%0A        self.target = target%0A        if config is None:%0A            config = get_default_sess_config()
 %0A   

change default config for NewSessionCreator (#191)