# Path: clustertools/util.py
# @contextmanager
# def catch_logging():
#     # Memo
#     logger = logging.getLogger("clustertools")
#     handlers = logger.handlers
#     level = logger.level
#     # New stuff
#     logger.handlers = []
#     ch = logging.StreamHandler(sys.stdout)
#     ch.setLevel(logging.DEBUG)
#     formatter = logging.Formatter("%(asctime)s - %(name)s - "
#                                   "%(levelname)s - %(message)s")
#     ch.setFormatter(formatter)
#     logger.addHandler(ch)
#     logger.setLevel(logging.DEBUG)
# 
#     try:
#         yield
#     finally:
#         logger.handlers = handlers
#         logger.level = level
# 
# Path: clustertools/state.py
# class PendingState(State):
#     def get_name(self):
#         return __PENDING__
# 
#     def to_running(self):
#         return RunningState.from_(self)
# 
#     def is_not_up(self):
#         return LaunchableState.from_(self)
# 
# class AbortedState(State):
#     @classmethod
#     def from_(cls, state, exception):
#         return cls(state.comp_name, progress=state.progress,
#                    exception=exception)
# 
#     def __init__(self, comp_name, exception, progress=0.):
#         super().__init__(comp_name, progress)
#         self.exception = exception
# 
#     def get_name(self):
#         return __ABORTED__
# 
#     def __repr__(self):
#         return "{cls}(comp_name={comp_name}, progress={progress}, " \
#                "exception={exception})".format(cls=self.__class__.__name__,
#                                                comp_name=repr(self.comp_name),
#                                                progress=repr(self.progress),
#                                                exception=repr(self.exception))


import shutil
import sys
import os
import subprocess
import logging
import copy
import dill
            import socket
from time import time as epoch
from datetime import datetime
from abc import ABCMeta, abstractmethod
from shlex import quote as escape
from clustertools.util import catch_logging
from .state import PendingState, AbortedState
                         "'{cls}'"
                         "".format(exp_name=self.storage.exp_name,
                                   cls=repr(self.environment)))
        self.opened = True
        return self

    def run(self, lazy_computation):
        """

        Parameters
        ----------
        lazy_computation

        Returns
        -------
        success: bool
            Whether launching the `lazy_computation` was (apparently) a
            success
        """
        if not self.is_open():
            raise ValueError("The session has not been opened.")
        try:
            if self.update_state:
                self.storage.update_state(PendingState(
                    lazy_computation.comp_name))
            self.logger.debug("Launching '{}'""".format(repr(lazy_computation)))
            self.environment.issue(lazy_computation)
            self.n_launch += 1
        except Exception as exception:
            if self.update_state:

# Path: clustertools/util.py
# @contextmanager
# def catch_logging():
#     # Memo
#     logger = logging.getLogger("clustertools")
#     handlers = logger.handlers
#     level = logger.level
#     # New stuff
#     logger.handlers = []
#     ch = logging.StreamHandler(sys.stdout)
#     ch.setLevel(logging.DEBUG)
#     formatter = logging.Formatter("%(asctime)s - %(name)s - "
#                                   "%(levelname)s - %(message)s")
#     ch.setFormatter(formatter)
#     logger.addHandler(ch)
#     logger.setLevel(logging.DEBUG)
# 
#     try:
#         yield
#     finally:
#         logger.handlers = handlers
#         logger.level = level
# 
# Path: clustertools/state.py
# class PendingState(State):
#     def get_name(self):
#         return __PENDING__
# 
#     def to_running(self):
#         return RunningState.from_(self)
# 
#     def is_not_up(self):
#         return LaunchableState.from_(self)
# 
# class AbortedState(State):
#     @classmethod
#     def from_(cls, state, exception):
#         return cls(state.comp_name, progress=state.progress,
#                    exception=exception)
# 
#     def __init__(self, comp_name, exception, progress=0.):
#         super().__init__(comp_name, progress)
#         self.exception = exception
# 
#     def get_name(self):
#         return __ABORTED__
# 
#     def __repr__(self):
#         return "{cls}(comp_name={comp_name}, progress={progress}, " \
#                "exception={exception})".format(cls=self.__class__.__name__,
#                                                comp_name=repr(self.comp_name),
#                                                progress=repr(self.progress),
#                                                exception=repr(self.exception))


# Path: clustertools/environment.py
import shutil
import sys
import os
import subprocess
import logging
import copy
import dill
            import socket
from time import time as epoch
from datetime import datetime
from abc import ABCMeta, abstractmethod
from shlex import quote as escape
from clustertools.util import catch_logging
from .state import PendingState, AbortedState

                         "'{cls}'"
                         "".format(exp_name=self.storage.exp_name,
                                   cls=repr(self.environment)))
        self.opened = True
        return self

    def run(self, lazy_computation):
        """

        Parameters
        ----------
        lazy_computation

        Returns
        -------
        success: bool
            Whether launching the `lazy_computation` was (apparently) a
            success
        """
        if not self.is_open():
            raise ValueError("The session has not been opened.")
        try:
            if self.update_state:
                self.storage.update_state(PendingState(
                    lazy_computation.comp_name))
            self.logger.debug("Launching '{}'""".format(repr(lazy_computation)))
            self.environment.issue(lazy_computation)
            self.n_launch += 1
        except Exception as exception:
            if self.update_state:

                self.storage.update_state(AbortedState(