(session, state_file, do_resume)
Resume a session if requested; save upon exit
Resume a session if requested; save upon exit
Resume a session if requested ; save upon exit
def manage_state(session, state_file, do_resume):
    """Resume a session if requested; save upon exit"""
    if do_resume and state_file:
        try:
            session = load_session(state_file).attach(session.interface)
        except Exception as e:
            # if we were told to resume but can't, give up
            logging.fatal('Failed to resume session from %s: %s', state_file, e)
            sys.exit(1)
    try:
        yield session
    finally:
        if state_file:
            try:
                save_session(session, state_file)
            except Exception as e:
                logging.error('Failed to save session to %s: %s', state_file, e)
def manage_state ( session , state_file , do_resume ) : if do_resume and state_file : try : session = load_session ( state_file ) . attach ( session . interface ) except Exception as e : # if we were told to resume but can't, give up logging . fatal ( 'Failed to resume session from %s: %s' , state_file , e ) sys . exit ( 1 ) try : yield session finally : if state_file : try : save_session ( session , state_file ) except Exception as e : logging . error ( 'Failed to save session to %s: %s' , state_file , e )