def new_from_parent(parent_state):
        """
        Create new state from parent state. Parent's enclosing environ are merged as
        part of child's environ
        :param ShState parent_state: Parent state
        :return:
        """

        if parent_state.enclosing_aliases:
            aliases = parent_state.enclosing_aliases
        else:
            aliases = dict(parent_state.aliases)

        if parent_state.enclosing_environ:
            environ = parent_state.enclosing_environ
        else:
            environ = dict(parent_state.environ)
            environ.update(parent_state.temporary_environ)

        if parent_state.enclosing_cwd:
            os.chdir(parent_state.enclosing_cwd)

        return ShState(
            aliases=aliases,
            environ=environ,
            enclosed_cwd=os.getcwd(),
            sys_stdin=parent_state.sys_stdin__,
            sys_stdout=parent_state.sys_stdout__,
            sys_stderr=parent_state.sys_stderr__,
            sys_path=parent_state.sys_path[:]
        )

        Create new state from parent state. Parent's enclosing environ are merged as
        part of child's environ
        :param ShState parent_state: Parent state
        :return:
        
system/shthreads.py