工作者线程从队列中读取的写入进度

2024-09-28 20:47:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一堆python线程从队列a-lahttps://gist.github.com/bsphere/f1e0a7d033dab2871c5c中读取。我想每10秒显示一次进度。这是迄今为止我发现的最好的了,有没有什么比这更冗长、更恶毒的

编辑:抱歉,我不太清楚-我对一个漂亮的UI不感兴趣,我只关心如何正确地与线程交互,而不存在并发错误,以便在等待工作线程完成时从主线程写入进度

threads = []
for i in xrange(NUMBER_OF_WORKERS):
    t = MyThread()
    threads.append(t)
    t.start()
live_threads = True
while live_threads:
    live_threads = False
    for t in threads:
        t.join(10)
        if t.isAlive():
            live_threads = True
            break
    logger.info("queue size: %s", q.qsize())

Tags: ingithubcomlivetruefor队列线程