Watch out for this common generator pitfall.
What happens to a try/finally, with block, or async with block inside a generator if the generator isn't exhausted? Does the cleanup code still run? When and how does it run? In this video we take a look at the answers to these questions and learn how to avoid a common situation where cleanup code doesn't run when you want it to.
― mCoding with James Murphy (
https://mcoding.io)PEP 533:
https://peps.python.org/pep-0533/Discussion on GH issue:
https://github.com/python/cpython/issues/88684Source code:
https://github.com/mCodingLLC/VideosSampleCodeSUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
https://patreon.com/mCodingFeeling generous but don't have a Patreon? Donate via PayPal! (No sign up needed.)
https://www.paypal.com/donate/?hosted_button_id=VJY5SLZ8BJHEEWant to donate crypto? Check out the rest of my supported donations on my website!
https://mcoding.io/donateTop patrons and donors: Laura M, Neel R, Dragos C, Jameson, Matt R, Pi, Vahnekie, Johan A, Mark M, Mutual Information
BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord:
https://discord.gg/Ye9yJtZQuNGithub:
https://github.com/mCodingLLC/Reddit:
https://www.reddit.com/r/mCoding/Facebook:
https://www.facebook.com/james.mcodingCHAPTERS
---------------------------------------------------
0:00 Intro
1:21 The cleanup question
5:30 The async case