Stopping the FIFO readout.

        Stopping of the FIFO readout is executed only once by a random thread.
        Stopping of the FIFO readout is synchronized between all threads reading out the FIFO.
544439
def stop_readout(self, timeout=10.0):
        ''' 
        '''
        if self._scan_threads and self.current_module_handle not in [t.name for t in self._scan_threads]:
            raise RuntimeError('Thread name "%s" is not valid.')
        if self._scan_threads and self.current_module_handle not in self._curr_readout_threads:
            raise RuntimeError('Thread "%s" is not reading FIFO.')
        with self._readout_lock:
            self._curr_readout_threads.remove(self.current_module_handle)
        self._stopping_readout_event.clear()
        while not self._stopping_readout_event.wait(0.01):
            with self._readout_lock:
                if len(set(self._curr_readout_threads) & set([t.name for t in self._scan_threads if t.is_alive()])) == 0 or not self._scan_threads or self.abort_run.is_set():
                    if self.fifo_readout.is_running:
                        self.fifo_readout.stop(timeout=timeout)
                    self._stopping_readout_event.set()
1255170
void free(ClientSocket stream)
  {
    success();

    _activeCount.decrementAndGet();

    synchronized (this) {
      int size = (_idleHead - _idleTail + _idle.length) % _idle.length;

      if (_state != State.CLOSED && size < _idleSize) {
        _idleHead = (_idleHead + 1) % _idle.length;
        _idle[_idleHead] = stream;

        stream = null;
      }

      long now = CurrentTime.currentTime();

      long prevSuccessTime = _prevSuccessTime;

      if (prevSuccessTime > 0) {
        _latencyFactor = (0.95 * _latencyFactor
                          + 0.05 * (now - prevSuccessTime));
      }

      if (_activeCount.get() > 0)
        _prevSuccessTime = now;
      else
        _prevSuccessTime = 0;

      _lastSuccessTime = now;
      
      if (log.isLoggable(Level.FINEST)) { 
        logFinest(L.l("free: _lastSuccessTime={0}, _failTime={1}",
                      now, _failTime));
      }
    }

    updateWarmup();

    long now = CurrentTime.currentTime();
    long maxIdleTime = _loadBalanceIdleTime;
    ClientSocket oldStream = null;

    do {
      oldStream = null;

      synchronized (this) {
        if (_idleHead != _idleTail) {
          int nextTail = (_idleTail + 1) % _idle.length;

          oldStream = _idle[nextTail];

          if (oldStream != null
              && oldStream.getIdleStartTime() + maxIdleTime < now) {
            _idle[nextTail] = null;
            _idleTail = nextTail;
          }
          else
            oldStream = null;
        }
      }

      if (oldStream != null)
        oldStream.closeImpl();
    } while (oldStream != null);

    if (stream != null) {
      stream.closeImpl();
    }
  }
261690
def stop_receive(self, stream):
        
        _vv and IOLOG.debug('%r.stop_receive(%r)', self, stream)
        self.defer(self.poller.stop_receive, stream.receive_side.fd)
1167293
def thread_stopped(self):
		
		tracker = self.tracker_storage()
		if tracker is not None:
			try:
				if self.ready_event().is_set() is True:
					if self.track_stop() is True:
						details = self.event_details(WTrackerEvents.stop)
						tracker.register_stop(self, event_details=details)
				elif self.exception_event().is_set() is False:
					if self.track_termination() is True:
						details = self.event_details(WTrackerEvents.termination)
						tracker.register_termination(self, event_details=details)
			except Exception as e:
				self.thread_tracker_exception(e)
131113
private void pauseOrResumeReading() {
        int bytesWaiting;
        synchronized (lock) {
            bytesWaiting = waitingAppends.values()
                    .stream()
                    .mapToInt(a -> a.getData().readableBytes())
                    .sum();
        }

        if (bytesWaiting > HIGH_WATER_MARK) {
            log.debug("Pausing writing from connection {}", connection);
            connection.pauseReading();
        }
        if (bytesWaiting < LOW_WATER_MARK) {
            log.trace("Resuming writing from connection {}", connection);
            connection.resumeReading();
        }
    }
7944
def _loop_once(self, timeout=None):
        
        _vv and IOLOG.debug('%r._loop_once(%r, %r)',
                            self, timeout, self.poller)
        #IOLOG.debug('readers =\n%s', pformat(self.poller.readers))
        #IOLOG.debug('writers =\n%s', pformat(self.poller.writers))
        for side, func in self.poller.poll(timeout):
            self._call(side.stream, func)
1050891
public synchronized void stop()
    {
        _started=false;

        if (_out!=null)
        {
            try
            {
                if (_buffer.size()>0)
                {
                    _buffer.writeTo(_out);
                }
                _out.flush();
                _buffer=null;
            }
            catch(Exception e){if (_logImpl!=null && _logImpl.getDebug())e.printStackTrace();}
            Thread.yield();
        }
        
        if (_out!=null && _out!=LogStream.STDERR_STREAM)
        {
            try{_out.close();}
            catch(Exception e){if (_logImpl!=null && _logImpl.getDebug())e.printStackTrace();}
        }

        if (_filename!=null)
            _out=null;
    }
402322
def halted(self):
        
        result = int(self._dll.JLINKARM_IsHalted())
        if result < 0:
            raise errors.JLinkException(result)

        return (result > 0)
135458
protected synchronized int read() throws IOException {
		try {
			block();
		} catch (InterruptedException ex) {
			throw new InterruptedIOException(
					"The blocking operation was interrupted");
		}

		if (closed && available() <= 0) {
			return -1;
		}

		return buf[readpos++];

	}
135644
def cancel():
    
    cancel = threading.Event()

    def cancel_execution(signum, frame):
        signame = SIGNAL_NAMES.get(signum, signum)
        logger.info("Signal %s received, quitting "
                    "(this can take some time)...", signame)
        cancel.set()

    signal.signal(signal.SIGINT, cancel_execution)
    signal.signal(signal.SIGTERM, cancel_execution)
    return cancel
144575
def loop_stop(self, force=False):
        
        if self._thread is None:
            return MQTT_ERR_INVAL

        self._thread_terminate = True
        self._thread.join()
        self._thread = None
319213
@Override
    public void stop() {
        try {
            if (randomAccessFile != null) {
                randomAccessFile.close();
                fileChannel.close();
            }
            randomAccessFile = null;
            fileChannel = null;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
885753
public void stop() {
    if (inputThread != null) {
      if (inputStreamPumper != null) {
        inputStreamPumper.stopProcessing();
      }
      // #33 Interrupt reading from a PipedInputStream to unblock the pumping thread
      inputThread.interrupt();
      log.trace("Joining input thread {}...", inputThread);
      try {
        inputThread.join();
        inputThread = null;
      }
      catch (InterruptedException e) {
        // ignore
      }
    }

    if (outputThread != null) {
      log.trace("Joining output thread {}...", outputThread);
      try {
        outputThread.join();
        outputThread = null;
      }
      catch (InterruptedException e) {
        // ignore
      }
    }

    if (errorThread != null) {
      log.trace("Joining error thread {}...", errorThread);
      try {
        errorThread.join();
        errorThread = null;
      }
      catch (InterruptedException e) {
        // ignore
      }
    }

    flush();
  }
178606
private final void flushBuffer() throws IOException {
		if (bufOutput.position() > 0) {
			bufOutput.flip();
			fcOutput.write(bufOutput);
			bufOutput.clear();
			// log.debug("offsetOutputUncommited=" + offsetOutputUncommited + " offsetOutputCommited=" +
			// offsetOutputCommited + " fcOutput.position()=" + fcOutput.position());
			offsetOutputUncommited = offsetOutputCommited = fcOutput.position();
			if (syncOnFlush) {
				fcOutput.force(false);
				if (callback != null) {
					callback.synched(offsetOutputCommited);
				}
			}
		}
	}
282912
private void handleReadBuffer() throws IOException {
        if (readBuffer.remaining() == 0) {
            readBuffer.clear();
            actualFile.read(actualFileOffset, readBuffer);
            actualFileOffset += readBuffer.limit();
            readBuffer.position(0);
        }
    }
911495
public void stop() {
    if (stopRequested) {
      return;
    }
    stopRequested = true;
    running = false;
    if (server != null) server.stop();
    if (triggerThread != null) {
      triggerThread.interrupt();
      triggerMonitor = null;
    }
    if (urfThread != null) {
      urfThread.interrupt();
      urfProcessor = null;
    }
    if (blockIntegrityMonitor != null) blockIntegrityMonitor.running = false;
    if (blockFixerThread != null) blockFixerThread.interrupt();
    if (blockCopierThread != null) blockCopierThread.interrupt();
    if (corruptFileCounterThread != null) corruptFileCounterThread.interrupt();
    if (purgeMonitor != null) purgeMonitor.running = false;
    if (purgeThread != null) purgeThread.interrupt();
    if (placementMonitor != null) placementMonitor.stop();
    if (statsCollector != null) statsCollector.stop();
    if (statsCollectorThread != null) statsCollectorThread.interrupt();
    if (infoServer != null) {
      try {
        infoServer.stop();
      } catch (Exception e) {
        LOG.warn("Exception shutting down " + RaidNode.class, e);
      }
    }
    this.unregisterMBean();
  }
1198972
def _handle_stderr(self, ioloop, f, count=-1):
        
        output = non_blocking_read(self._popen.stderr, count)
        if not output:
            self._popen.stderr.close()
            self._popen.stderr = None
        else:
            self._error.write(output)
            self._register_stderr(ioloop)