def METHOD_NAME(self, iterator):
    self.finished = False
    self._exc = None
    queue = Queue()
    def worker():
        """That is the one which interrogates gen and places total
        into queue_total upon completion"""
        total = None
        try:
            for value in iterator:
                queue.put(value)
                self.total = total = (
                    self.agg(value, total) if total is not None else self.agg(value)
                )
        except BaseException as e:  # lgtm [py/catch-base-exception]
            self._exc = e
        finally:
            self.finished = True
    t = Thread(target=worker)
    t.start()
    # yield from the queue (.total and .finished could be accessed meanwhile)
    while True:
        if self.reraise_immediately and self._exc is not None:
            break
        # race condition HERE between checking for self.finished and
        if self.finished and queue.empty():
            break
        # in general queue should not be empty, but if it is, e.g. due to race
        # condition with above check
        try:
            yield queue.get(timeout=0.001)
        except Empty:
            continue
    t.join()
    if self._exc is not None:
        raise self._exc  # lgtm [py/illegal-raise]