def circuitDestroyed(self, circuit):
        '''Circuits call circuitDestroyed() when they have cleaned up after
        themselves and closed.

        Circuits may need to do a number of things before references to
        them are completely removed. Exactly what steps a circuit needs to
        take before being fully destroyed depend on both the circuit's state
        and the state of the whole program. After a circuit has fully cleaned
        up after itself and taken all necessary closing actions, it calls
        CircuitManager.circuitDestroyed().

        circuitDestroyed() does three things:

            1. Remove the closed circuit from any internal maps.

            2. Check the pool of pending requests. If any pending requests
               exist that cannot be handled by any open or pending circuits,
               begin building a new circuit to handle these orphaned requests.
               This can happen when a circuit is built to handle a particular
               request but is then destroyed/an error occurs while it is being
               built.

            3. Check CircuitManager's basic open and pending circuit
               requirements to see if a new circuit of a certain type should
               be built. For instance, if an IPv4 circuit closes and the
               number of open and pending IPv4 circuits is below
               self._min_IPv4_count, a new IPv4 circuit will be built.

        :param circuit_id: id of circuit to be destroyed
        :type circuit_id: int
        '''
        cid = circuit.circuit_id
        try:
            del self._circuit_build_task_dict[cid]
            msg = "Destroyed CircuitBuildTask {}.".format(cid)
            logging.debug(msg)
        except __HOLE__:
            try:
                del self._open_circuit_dict[cid]
                msg = "Destroyed open circuit {}.".format(cid)
                logging.debug(msg)
            except KeyError:
                msg = ("Circuit manager was notified that circuit {} was "
                       "destroyed, but manager has no reference to that "
                       "circuit.".format(cid))
                logging.debug(msg)
                return

        self._assignAllPossiblePendingRequests()
        self._buildCircuitsForOrphanedPendingRequests()
        self._replenishCircuits()

    # TODO: fix/update docs
dataset/ETHPy150Open nskinkel/oppy/oppy/circuit/circuitmanager.py/CircuitManager.circuitDestroyed