多线程异常卡死求助

tech2022-09-08  99

当我在q队列中取出一个0时就卡死了,怎么跳过再取下一个???

class saver(threading.Thread): def __init__(self, q): super(saver, self).__init__() self.q = q def run(self) -> None: global n while True: try: y = self.q.get() glock.acquire() n = n + 1 print(y) print(1/y) print('%d次计算' % n) glock.release() except Exception as e: print(e) def main(): ls = [random.randint(0, 5) for i in range(20)] q = queue.Queue() for l in ls: q.put(l) for x in range(5): th = saver(q) th.start() if __name__ == '__main__': main()

当我在q队列中取出一个0时就卡死了,怎么跳过再取下一个???

最新回复(0)