'Run the collector method using the worker pool. The collect_once method will receive \'G\' as
its first argument, followed by the provided args, if any. The method should return a pair of values.
The first should be the object to be collected, and the second is the increment to be added.
This will continue until the total increment reaches or exceeds the given threshold.
Sample script:
def collect_once(G):
return \'a\', 1
stateful_pool.run_collect(collect_once, threshold=3) # => [\'a\', \'a\', \'a\']
:param collector:
:param threshold:
:return:'

def run_collect(self, collect_once, threshold, args=None, show_prog_bar=True):

    if (args is None):
        args = tuple()
    if self.pool:
        manager = mp.Manager()
        counter = manager.Value('i', 0)
        lock = manager.RLock()
        results = self.pool.map_async(_worker_run_collect, ([(collect_once, counter, lock, threshold, args)] * self.n_parallel))
        if show_prog_bar:
            pbar = ProgBarCounter(threshold)
        last_value = 0
        while True:
            time.sleep(0.1)
            with lock:
                if (counter.value >= threshold):
                    if show_prog_bar:
                        pbar.stop()
                    break
                if show_prog_bar:
                    pbar.inc((counter.value - last_value))
                last_value = counter.value
        return sum(results.get(), [])
    else:
        count = 0
        results = []
        if show_prog_bar:
            pbar = ProgBarCounter(threshold)
        while (count < threshold):
            (result, inc) = collect_once(self.G, *args)
            results.append(result)
            count += inc
            if show_prog_bar:
                pbar.inc(inc)
        if show_prog_bar:
            pbar.stop()
        return results
