'Restore all unacknowledged messages at shutdown/gc collect.
Note:
Can only be called once for each instance, subsequent
calls will be ignored.'

def restore_unacked_once(self, stderr=None):

    self._on_collect.cancel()
    self._flush()
    stderr = (sys.stderr if (stderr is None) else stderr)
    state = self._delivered
    if ((not self.restore_at_shutdown) or (not self.channel.do_restore)):
        return
    if getattr(state, u'restored', None):
        assert (not state)
        return
    try:
        if state:
            print(RESTORING_FMT.format(len(self._delivered)), file=stderr)
            unrestored = self.restore_unacked()
            if unrestored:
                (errors, messages) = list(zip(*unrestored))
                print(RESTORE_PANIC_FMT.format(len(errors), errors), file=stderr)
                emergency_dump_state(messages, stderr=stderr)
    finally:
        state.restored = True
