Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book

#347: The One About Context Mangers

Published Tue, Aug 8, 2023, recorded Tue, Aug 8, 2023
Watch this episode on YouTube
Play on YouTube
Watch the live stream replay

About the show

Sponsored by us! Support our work through:

Connect with the hosts

Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too.

Michael #1: async-timeout

  • An asyncio-compatible timeout context manager.
  • The context manager is useful in cases when you want to apply timeout logic around block of code or in cases when asyncio.wait_for() is not suitable.
  • Not finished yet timeout can be rescheduled by shift_by() or shift_to() methods

Brian #2: PyPI Project URLs Cheatsheet

  • Daniel Roy Greenfield
  • There’s some cool icons available under “Project Links” on pypi.org project pages.
  • How do you get those? And which ones are available.
  • Daniel has found out where to look, and built us a cheat sheet. Nice.

Michael #3: httpx-sse

Brian #4: Creating a context manager in Python

  • Trey Hunner
  • Context managers are those things you use in a with block.
  • There’s a bunch of cool built in ones.
  • Building your own is a handy skill to have to clean up your code, and they’re pretty easy, with Trey’s tutorial.
  • Shown is a great example of temporarily modifying an environmental variable.
  • Then he gets into what you need to know about as, __enter__, and __exit__.

Extras

Brian:

  • I think I’ll nix the intro music to Python People. I didn’t know what music to use, so I re-used the music from Test & Code. And I got some very honest feedback that it just doesn’t fit and was better without it. So I’ll rip it out soon.
  • BTW, next episode to be released is with Bob Belderbos from PyBites. Should be later this week.

Michael:

Joke:


Want to go deeper? Check our projects