A lunchtime story to demonstrate threading, asyncio, multiprocessing & cloud functions
I’m going to tell a story to explain the different concurrency and parallelism options in Python.
In this story we will see how a single person multitasking is like concurrency, and multiple people doing their own tasks is like parallelism. We’ll watch these scenarios in action at some well known lunchtime restaurants as they quickly and efficiently serve their customers. Then I’ll implement these restaurants in Python, and finally I’ll compare the different concurrency options and explain when to use each one.
When starting a new Python project, it is tempting to just dive in and start coding. Spending a tiny amount of time to set up a project with the best tools will save immense time and lead to a happier coding experience.
In an ideal world, dependencies would be identical for all developers, code would be perfectly formatted, common errors forbidden and everything would be covered by tests. Additionally, all of these would be ensured at each commit.
In this article, I’ll go through how to set up a project that does exactly that. You can either follow along with…
Refactoring is the process of improving the quality of code without changing what it does. Taking a little bit of time to refactor your code before committing it can make it much more readable, which makes it easier to maintain. Doing this consistently turns finding bugs and adding new features from a nightmarish hellscape into a walk in the park.
Ideally your code will be fully covered with unit tests, allowing you to make changes with confidence. If it isn’t then you should add tests before starting to refactor if at all possible. …