'Remove the channel from the dict of channels when Channel.CloseOk is
sent. If connection is closing and no more channels remain, proceed to
`_on_close_ready`.
:param pika.channel.Channel channel: channel instance'

def _on_channel_cleanup(self, channel):

    try:
        del self._channels[channel.channel_number]
        LOGGER.debug('Removed    channel    %s', channel.channel_number)
    except KeyError:
        LOGGER.error('Channel    %r    not    in    channels', channel.channel_number)
    if self.is_closing:
        if (not self._channels):
            self._on_close_ready()
        else:
            channels_not_in_closing_state = [chan for chan in dict_itervalues(self._channels) if (not chan.is_closing)]
            if channels_not_in_closing_state:
                LOGGER.critical('Connection    in    CLOSING    state    has    non-CLOSING    channels:    %r', channels_not_in_closing_state)
