Python 3.11: A Guided Tour Through Code Transcripts
Chapter: Error Handling Improvements and except*
Lecture: Except* is not Just for Async

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now the example that I gave you was exception groups and except star for async, you might be thinking I never do async stuff.
0:09 So not my problem. I don't care the idea of these except stars and exception groups certainly could be expanded
0:18 and may be expanded in certain libraries beyond that. So for example,
0:23 obviously we have the concurrency story that we spoke about but you might also have the retry operations.
0:31 Have you heard of the library package Tenacity? It comes with the decorator that you can put onto a function
0:37 that says I'm gonna call this function and if it fails, try it again fails again, try it again up to five times and maybe slow down and call it more
0:46 slowly. Like maybe the database server is being restarted and you need a 10sec window so try it.
0:53 But if that fails, slow down, but if it ultimately tries five times and then does completely fail,
0:59 you might want to know all five errors. So multiple failures when retraining operation,
1:04 that would work really well with exception groups and except star. If you have multiple user callbacks fail, for example,
1:12 you can register at exit and potentially multiple exits could fail.
1:17 You might want to know what's going on here. There are multiple errors in some kind of complex calculation or
1:26 in wrapper code, for example, the temp file temp directory context manager had a problem while processing exception,
1:34 it couldn't clean up. So it raised its own exception. In addition to the exception exception that caused it to clean up,
1:40 you might want to know about both of those. That's just some of the ideas of how you might use
1:44 except Star and except exception groups. That is not just concurrency.


Talk Python's Mastodon Michael Kennedy's Mastodon