'Flush all queues.
Including the outbound buffer, so that
all tasks that haven\'t been started will be discarded.
In Celery this is called whenever the transport connection is lost
(consumer restart), and when a process is terminated.'

def process_flush_queues(self, proc):

    resq = proc.outq._reader
    on_state_change = self._result_handler.on_state_change
    fds = {resq}
    while (fds and (not resq.closed) and (self._state != TERMINATE)):
        (readable, _, _) = _select(fds, None, fds, timeout=0.01)
        if readable:
            try:
                task = resq.recv()
            except (OSError, IOError, EOFError) as exc:
                _errno = getattr(exc, u'errno', None)
                if (_errno == errno.EINTR):
                    continue
                elif (_errno == errno.EAGAIN):
                    break
                elif (_errno not in UNAVAIL):
                    debug(u'got    %r    while    flushing    process    %r', exc, proc, exc_info=1)
                break
            else:
                if (task is None):
                    debug(u'got    sentinel    while    flushing    process    %r', proc)
                    break
                else:
                    on_state_change(task)
        else:
            break
