aioredis.Channel.wait_message()抛出的异常是什么?



我有一个代码段如下所示,它能够在抛出异常之前每次获得6条消息。但是,我无法确定正在抛出的异常是什么;我已经打印出了'True outside',所以看起来异常是在wait_message()中抛出的,但是"except exception作为"没能抓住它。有人能帮忙吗?

redisS  = await aioredis.create_connection(('localhost', 6379)) 
subCh   = aioredis.Channel(self._redis, is_pattern=False)
await redisS.execute_pubsub('subscribe', subCh)
try:
while await subCh.wait_message():
try:
msg = await subCh.get()
for q in self._queues:
await q.put(msg)
except:
print('inside')
except aioredis.ChannelClosedError:
print(subCh.is_active)
print('ChannelClosedError')
except Exception as e:
print(subCh.is_active)
print(e)
except:
print(subCh.is_active)
print('outside')

抱歉,我有答案了。一开始,我试着

except:
print(sys.exc_info()[0])

然后我有了'GeneratorExit'>类。因此,我最终可以通过

捕获异常
except GeneratorExit:
print('caught you')

最新更新