[issue45894] exception lost when loop.stop() in finally

2021-11-24 Thread Amos Anderson
Amos Anderson added the comment: Ah, thank you, Serhiy. I didn't know that, but I see that in the documentation: https://docs.python.org/3/reference/compound_stmts.html#the-try-statement But what about the 2nd case I presented where a `RuntimeError` was raised? That's the actual case I'm

[issue45894] exception lost when loop.stop() in finally

2021-11-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It is not related to loop.stop() and asyncio in general. It is the return statement which eats the exception. Simpler example: >>> def f(): ... try: ... 1/0 ... finally: ... return 42 ... >>> f() 42 Return (and also break and

[issue45894] exception lost when loop.stop() in finally

2021-11-24 Thread Amos Anderson
Amos Anderson added the comment: If I do this instead: ``` try: logger.info("raising exception") raise ValueError("my exception1") finally: logger.info("stopped") loop.stop() await asyncio.sleep(0.5) ``` i.e., do an `await` instead of a

[issue45894] exception lost when loop.stop() in finally

2021-11-24 Thread Amos Anderson
New submission from Amos Anderson : I found a case where an exception is lost if the loop is stopped in a `finally`. ``` import asyncio import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger() async def method_that_raises(): loop = asyncio.get_event_loop()