Why not using "except: (...) raise" to cleanup on error?
4 Jun
2018
4 Jun
'18
4:11 p.m.
Hi, I just read a recent bugfix in asyncio: https://github.com/python/cpython/commit/9602643120a509858d0bee4215d7f150e61... + try: + await waiter + except Exception: + transport.close() + raise Why only catching "except Exception:"? Why not also catching KeyboardInterrupt or MemoryError? Is it a special rule for asyncio, or a general policy in Python stdlib? For me, it's fine to catch any exception using "except:" if the block contains "raise", typical pattern to cleanup a resource in case of error. Otherwise, there is a risk of leaking open file or not flushing data on disk, for example. Victor
2145
Age (days ago)
2145
Last active (days ago)
10 comments
5 participants
participants (5)
-
Chris Angelico
-
Guido van Rossum
-
Ivan Pozdeev
-
Victor Stinner
-
Yury Selivanov