Speed up your Python code in just 5 lines of code using concurrent.futures

Опубликовано: 10 Октябрь 2024
на канале: Pybites
3,093
46

In this video we quickly demo how to use concurrent.futures' ThreadPoolExecutor() context manager to significantly speeding up downloading of our articles.

We hit a 4x speed increase, but tuning its settings you might even gain more. Of course be mindful how you use this to not cause too many requests to a web server.

However, you can use it with any callable (function) and we've seen people making other people really happy by the performance boost it provided in just ~5 lines of code!

Code (cleaned it up a bit): https://gist.github.com/bbelderbos/1b...
Docs: https://docs.python.org/3/library/con...
Request headers: https://stackoverflow.com/a/27652558
Our Python tips book: https://pybit.es/tips/

---
We appreciate any feedback 💡 - please use this form so we can always make our content better:
https://form.jotform.com/230941798741062 🙏