Deal with session ready for the read or write operations, or both.
348252
private void process(T session) {
        // Process Reads
        if (isReadable(session) && !session.isReadSuspended()) {
            read(session);
        }

        // Process writes
        if (isWritable(session) && !session.isWriteSuspended()) {
            scheduleFlush(session);
        }
    }
558916
def session(self):
        
        engine = self.engine
        connection = engine.connect()
        db_session = scoped_session(
            sessionmaker(autocommit=False, autoflush=True, bind=engine))
        yield db_session
        db_session.close()
        connection.close()
1314899
protected void checkValidForRead() throws IllegalStateException {
        checkLocked();

        if (state == State.INVALID) {
            throw new IllegalStateException("Invalid for read: session " + this);
        }
        if (state == State.INVALIDATING) {
            return;
        }
        if (!isResident()) {
            throw new IllegalStateException("Invalid for read: session " + this);
        }
    }
977247
private void cleanupSession(){
        eventThread.queueClientEvent(new ClientSessionEvent(SessionEvent.CLOSED));
        watcherManager.cleanup();
        session.id = "";
        session.password = null;
        session.serverId = -1;
        onSessionClose();
    }
1348895
def _ensure_session(self, session=None):
        """"""
        if session:
            return session

        try:
            # Don't make implicit sessions causally consistent. Applications
            # should always opt-in.
            return self.__start_session(True, causal_consistency=False)
        except (ConfigurationError, InvalidOperation):
            # Sessions not supported, or multiple users authenticated.
            return None
208870
def session_scope(session_cls=None):
    """"""
    session = session_cls() if session_cls else Session()
    try:
        yield session
        session.commit()
    except Exception:
        session.rollback()
        raise
    finally:
        session.close()
543650
def check_session(self):
        
        if self.session is None:
            if self.autosession:
                self.open_session()
            else:
                msg = "must open a session before modifying %s" % self
                raise RuntimeError(msg)
836555
public final void setupResend() {
    // First, reset the current write op, or cancel it if we should
    // be authenticating
    Operation op = getCurrentWriteOp();
    if (shouldAuth && op != null) {
      op.cancel();
    } else if (op != null) {
      ByteBuffer buf = op.getBuffer();
      if (buf != null) {
        buf.reset();
      } else {
        getLogger().info("No buffer for current write op, removing");
        removeCurrentWriteOp();
      }
    }
    // Now cancel all the pending read operations. Might be better to
    // to requeue them.
    while (hasReadOp()) {
      op = removeCurrentReadOp();
      if (op != getCurrentWriteOp()) {
        getLogger().warn("Discarding partially completed op: %s", op);
        op.cancel();
      }
    }

    while (shouldAuth && hasWriteOp()) {
      op = removeCurrentWriteOp();
      getLogger().warn("Discarding partially completed op: %s", op);
      op.cancel();
    }

    getWbuf().clear();
    getRbuf().clear();
    toWrite = 0;
  }
43441
def _initialize_session():
    # type: () -> None
    
    sys_random = random.SystemRandom()
    _thread_local_storage.secret_key = b''.join(
        int2byte(sys_random.randint(0, 255))
        for _ in range(SECRET_KEY_BITS // 8))
89067
private void handleReadsAndWrites(final SelectionKey sk, final MemcachedNode node) throws IOException {
      if (sk.isValid() && sk.isReadable()) {
          handleReads(node);
      }

      if (sk.isValid() && sk.isWritable()) {
          handleWrites(node);
      }
  }
679373
def session_scope(self):
        """"""
        session = self.session()
        try:
            yield session
            session.commit()
        except Exception as e:
            session.rollback()
            raise e
        finally:
            session.close()
354826
def handle_remove_readonly(func, path, exc):
    """"""
    # Check for read-only attribute
    default_warning_message = (
        "Unable to remove file due to permissions restriction: {!r}"
    )
    # split the initial exception out into its type, exception, and traceback
    exc_type, exc_exception, exc_tb = exc
    if is_readonly_path(path):
        # Apply write permission and call original function
        set_write_bit(path)
        try:
            func(path)
        except (OSError, IOError) as e:
            if e.errno in [errno.EACCES, errno.EPERM]:
                warnings.warn(default_warning_message.format(path), ResourceWarning)
                return

    if exc_exception.errno in [errno.EACCES, errno.EPERM]:
        warnings.warn(default_warning_message.format(path), ResourceWarning)
        return

    raise exc
1288376
public void sessionOpened(IoSession session) throws Exception {
        SingleSessionIoHandler handler = (SingleSessionIoHandler) session
                .getAttribute(HANDLER);
        handler.sessionOpened();
    }
924508
def session(self):
        """"""
        if self._session is None:
            from .tcex_session import TcExSession

            self._session = TcExSession(self)
        return self._session
996902
private void makeReadWrite(final Session session)
	{
		session.doWork(SetJDBCConnectionReadOnlyWork.READ_WRITE);
		session.setHibernateFlushMode(FlushMode.AUTO);
	}
1318207
def set_session_info(self, info):
        '''
        
        '''
        if not self.info:
            self.info = SessionInfo()
            info_d = self.info.as_dict()
            ks = []
            vs = []
            for k, v in info_d.items():
                ks.append(k)
                vs.append(v)
            self.insert(ks, vs)
        changed = self.info.copy(info)
        if changed:
            self.update(self.info.as_dict())
191897
def saveSession(self, filepath):
        """"""
        try:
            session_module.Save(self.session, filepath)
        except RuntimeError as e:
            log.exception(e)
            os.remove(filepath)
            log.warning("Session not saved")