Pause until the socket `rsock` indicates readability, due to
        :meth:`_do_cork` triggering a blocking write on another thread.
438459
def _verify_one(self, rsock):
        
        poller = mitogen.core.Poller()
        poller.start_receive(rsock.fileno())
        try:
            while True:
                for fd in poller.poll():
                    return
        finally:
            poller.close()
877421
public function pauseRecv()
    {
        Worker::$globalEvent->del($this->_socket, EventInterface::EV_READ);
        $this->_isPaused = true;
    }
682252
function _socket(socket, keepAlive) {
    socket.setTimeout(0);
    socket.setNoDelay(true);

    if (keepAlive) {
      if (socket.setKeepAlive) {
        socket.setKeepAlive(true, 0);
      }
      else if (socket.pair.cleartext.socket.setKeepAlive) {
        socket.pair.cleartext.socket.setKeepAlive(true, 0);
      }
    }
  }
258346
def halt(self):
        
        if self._callback:
            self._thread_continue = False
            self._thread.join()
367279
def _wait_for_transfer_threads(self, terminate):
        # type: (SyncCopy, bool) -> None
        
        if terminate:
            self._synccopy_terminate = terminate
        for thr in self._transfer_threads:
            blobxfer.util.join_thread(thr)
1294448
def pause(self, uuid):
        
        args = {
            'uuid': uuid,
        }
        self._domain_action_chk.check(args)

        self._client.sync('kvm.pause', args)
109647
def _wait(self, args, now, cap, consumed_history, consumed_capacity):
        
        for key in ['read', 'write']:
            if key in cap and cap[key] > 0:
                consumed_history[key].add(now, consumed_capacity[key])
                consumed = consumed_history[key].value
                if consumed > 0 and consumed >= cap[key]:
                    seconds = math.ceil(float(consumed) / cap[key])
                    LOG.debug("Rate limited throughput exceeded. Sleeping "
                              "for %d seconds.", seconds)
                    if callable(self.callback):
                        callback_args = args + (seconds,)
                        if self.callback(*callback_args):
                            continue
                    time.sleep(seconds)
268632
def _on_fork(cls):
        
        cls._cls_idle_socketpairs = []
        while cls._cls_all_sockets:
            cls._cls_all_sockets.pop().close()
1269009
def readable(self, timeout=2):
        
        with self.lock:
            if len(self._buffer) > self._index:
                return True
            else:
                if self._select([self._socket], [], [], timeout)[0] == []:
                    return False
                else:
                    return True
271632
def stop(self):
        
        self.listener.setsockopt(LINGER, 1)
        self.loop = False
        with nslock:
            self.listener.close()
281941
def wait_for_at_least_one_message(self, channel):
        

        unpacker = msgpack.Unpacker(encoding='utf-8')

        while True:
            try:
                start = time.time()
                chunk = self.ssh_channel[channel].recv(1024)
                end = time.time()
                self.read_speeds.append( len(chunk) / (end-start) )
                if len(self.read_speeds) > 20:
                    self.read_speeds = self.read_speeds[10:]

                if chunk == b'':
                    # happens only when connection broke. If nothing is to be received, it hangs instead.
                    self.connection_error(channel, 'Connection broken w')
                    return False
            except Exception as error:
                self.connection_error(channel, error)
                raise

            unpacker.feed(chunk)

            messages = [m for m in unpacker]
            if messages:
                return messages
86116
def _reader_thread_func(self, read_stdout: bool) -> None:
        
        if read_stdout:
            read_stream = self._proc.stdout
            write_stream = self._stdout
        else:
            read_stream = self._proc.stderr
            write_stream = self._stderr

        # The thread should have been started only if this stream was a pipe
        assert read_stream is not None

        # Run until process completes
        while self._proc.poll() is None:
            # noinspection PyUnresolvedReferences
            available = read_stream.peek()
            if available:
                read_stream.read(len(available))
                self._write_bytes(write_stream, available)
461563
def write(s)
      if idle_timeout
        if (t=Time.now) > @last_write + idle_timeout
          @socket.close rescue nil
          connect
        else
          @last_write = t
        end
      end
      begin
        retry_id ||= 0
        do_write(s)
      rescue => e
        if (retry_id += 1) < @retries
          @socket.close rescue nil
          connect
          retry
        else
          raise e
        end
      end
    end
75460
def acquire_writer(self):
        
        with self.mutex:
            while self.rwlock != 0:
                self._writer_wait()
            self.rwlock = -1
852064
def watch
      until(@stop)
        begin
          resultset = Kernel.select(@sockets.keys, nil, nil, nil)
          for sock in resultset[0]
            string = sock.gets
            if(sock.closed? || string.nil?)
              if(@sockets[sock][:closed])
                @sockets[sock][:closed].each do |pr|
                  pr[1].call(*([sock]+pr[0]))
                end
              end
              @sockets.delete(sock)
            else
              string = clean? ? do_clean(string) : string
              process(string.dup, sock)
            end
          end
        rescue Resync
          # break select and relisten #
        end
      end
      @runner = nil
    end
96944
def _wait_event(self, reading):
        ""
        with self._registered(reading, not reading):
            (self._readable if reading else self._writable).wait()

        if scheduler.state.interrupted:
            raise IOError(errno.EINTR, "interrupted system call")
890087
void startRemotePut() {
    assert !_key.home();
    int x = 0;
    // assert I am waiting on threads with higher priority?
    while( (x=_rwlock.get()) != -1 ) // Spin until rwlock==-1
      if( x == 1 || RW_CAS(0,1,"remote_need_notify") )
        try { ForkJoinPool.managedBlock(this); } catch( InterruptedException e ) { }
  }