def _exit(self, await_non_daemons):
        """Internal use only.
        """
        if not self._quit:
            if await_non_daemons:
                if len(self._coros) > self._daemons:
                    logger.debug('waiting for %s coroutines to terminate',
                                 (len(self._coros) - self._daemons))
            else:
                self._lock.acquire()
                for coro in self._coros.itervalues():
                    if not coro._daemon:
                        coro._daemon = True
                        self._daemons += 1
                if len(self._coros) != self._daemons:
                    logger.warning('daemons mismatch: %s != %s', len(self._coros), self._daemons)
                self._complete.set()
                self._lock.release()

            self._complete.wait()
            if self._location:
                Coro(_Peer.shutdown, timeout=5)
                self._complete.wait()

            self._lock.acquire()
            if not self._quit:
                self._complete.clear()
                self._quit = True
                # add a dummy timeout so scheduler will not wait for any other
                # timeouts left behind by coroutines that may have quit already
                heappush(self._timeouts, (_time() + 0.1, None, None))
                self._lock.release()
                self._notifier.interrupt()
                self._complete.wait()
            else:
                self._lock.release()
dataset/ETHPy150Open pgiri/asyncoro/py2/asyncoro/__init__.py/AsynCoro._exit/original