我有一个队列和一个事件。 当事件设置为True时,我想退出循环,但循环中有一个queue.get()会一直阻塞直到队列中有东西。
当closeEvent事件标志被设置时,如何中止等待self._commandQueue.get()?
注意:我想避免依赖队列的阻塞性,并希望基于队列和事件标志的条件进行阻塞。
def _execute(self):
while not self._closeEvent.isSet():
nextCommand = self._commandQueue.get()
self._commandExecutor.execute(nextCommand)
self._commandQueue.task_done()