If we've exhausted our limit of threads, wait for one to finish.

@return void
761334
private function waitForAnyThread()
    {
        while (true) {
            foreach ($this->getPIDs() as $pid) {
                if (!$this->isRunning($pid)) {
                    return;
                }
            }

            # If none of the threads have finished let, wait for a second before checking again
            sleep(1);
        }
    }
220560
public function finish()
    {
        $this->xml_depth = 0;
        $this->current_ns = [];
        $this->idhandlers = [];
        $this->xpathhandlers = [];
        $this->eventHandlers = [];
    }
615598
public function end(): void
    {
        $this->isEnding = true;

        if ($this->pool->isEmpty()) {
            $this->close();
        }
    }
611188
public function start()
    {
        foreach ($this->processes as $process) {
            //start process
            $process->start();

            //update status array
            $this->updateStatus();

            while ($this->runningProcesses() >= $this->concurrent) {
                usleep(self::SLEEP_INTERVAL);
                //update status
                $this->updateStatus();
            }
        }
        //wait until all processes are finished
        $this->wait();
    }
681514
def wait_until_exit(self):
        

        if self._timeout is None:
            raise Exception("Thread will never exit. Use stop or specify timeout when starting it!")

        self._thread.join()
        self.stop()
4004
public function tick()
    {
        while (!$this->queue->isEmpty() && $this->loop->isRunning())
        {
            $this->callback = $this->queue->dequeue();
            $callback = $this->callback; // without this proxy PHPStorm marks line as fatal error.
            $callback($this->loop);
        }
    }
377797
def stop(self):
        
        if self._thread is not None and self._thread.isAlive():
            self._done.set()
861169
protected function limit()
    {
        if (($connectionLimit = config('ratchet.connectionLimit')) && $this->connections - 1 >= $connectionLimit) {
            $this->console->info(sprintf('To many connections: %d of %d', $this->connections - 1, $connectionLimit));
            $this->conn->send(trans('ratchet::messages.tooManyConnections'));
            $this->conn->close();
        }

        return $this;
    }
702569
def finish (self):
        """"""
        if not self.urlqueue.empty():
            # This happens when all checker threads died.
            self.cancel()
        for t in self.threads:
            t.stop()
678593
protected function pushLimit()
    {
        if( null !== $this->limit ) {
            if( null !== $this->offset ) {
                $this->parts[] = 'LIMIT ?, ?';
                $this->params[] = $this->offset;
                $this->params[] = $this->limit;
            } else {
                $this->parts[] = 'LIMIT ?';
                $this->params[] = $this->limit;
            }
        }
    }
561688
protected final void finish(Thread t) {
    if (t == null) {
      // nothing to terminate
      return;
    }
    try {
      StreamPumper s = null;
      if (t instanceof ThreadWithPumper) {
        s = ((ThreadWithPumper) t).getPumper();
      }
      if (s != null && s.isFinished()) {
        return;
      }
      if (!t.isAlive()) {
        return;
      }

      if (s != null && !s.isFinished()) {
        s.stop();
      }
      t.join(JOIN_TIMEOUT);
      while ((s == null || !s.isFinished()) && t.isAlive()) {
        t.interrupt();
        t.join(JOIN_TIMEOUT);
      }
    } catch (InterruptedException e) {
      // ignore
    }
  }
1084771
public function join()
    {
        while (true) {
            $finished = true;
            foreach ($this->processes as $pid => $process) {
                if ($process->isAlive()) {
                    $finished = false;
                    break;
                }
            }

            if ($finished) {
                break;
            }

            unset($finished);
            usleep(10000);
        }
    }
1220502
protected function fill()
    {
        if (count($this) <= 0) {
            return;
        }

        $read = $this->sockets;
        $write = null;
        $except = null;
        $time = count($this->results) > 0 ? 0 : $this->timeout;

        if (stream_select($read, $write, $except, $time) > 0) {
            foreach ($read as $socket) {
                try {
                    $result = $this->read($socket);
                } catch (\RuntimeException $e) {
                    continue;
                }
                $this->results->enqueue($result);
                $this->remain--;
            }
        }
    }
489144
private function startNext()
    {
        // this allows us to wait until all runs are added in the constructor before running any.
        // Thus preserving the priority they have supplied.
        if (!$this->initialised) {
            return;
        }

        if ($this->maxSimultaneous !== static::NO_MAX
            && $this->waitingQueue->valid()
            && count($this->running) < $this->maxSimultaneous) {
            for ($i = count($this->running); $i < $this->maxSimultaneous && $this->waitingQueue->valid(); $i++) {
                $this->startRun($this->waitingQueue->extract());
            }
        } elseif ($this->maxSimultaneous === static::NO_MAX) {
            while ($this->waitingQueue->valid()) {
                $this->startRun($this->waitingQueue->extract());
            }
        }
    }
258346
def halt(self):
        
        if self._callback:
            self._thread_continue = False
            self._thread.join()
288031
public void waitAndStopThreads()
    {
        try
        {
            if (threadMap.isEmpty())
            {
                throw new IllegalStateException("threads are already interrupted");
            }
            stopSemaphore.acquire(maxParallelism);
            stopThreads();
        }
        catch (InterruptedException ex)
        {
            throw new IllegalArgumentException(ex);
        }
    }
1363793
public function wait(): void
    {
        while (!$this->stream->eof()) {
            $frame = $this->readFrame();

            if (null !== $frame) {
                if (!\is_array($frame)) {
                    $frame = [$frame];
                }

                foreach ($this->onNewFrameCallables as $newFrameCallable) {
                    \call_user_func_array($newFrameCallable, $frame);
                }
            }
        }
    }