The technical term for what we’re discussing today is Decorated Concurrency. Don’t let this scare you! 😇 It’s just a fancy (and concise) way of saying that, “We have a simple way to do parallel processing.”
Parallel processing, in turn, means that we can start multiple threads, as needed, in our program such that everything runs faster. Behind-the-scenes, on modern processors that have multiple cores, Python can run different processes on different cores. This lets a developer decide which processes will run the fastest because they have their own core. Or, at a higher level, which functions/methods are candidates for running on multiple cores.
I’ve known about parallel processing in Python for some time but it has always required making special function calls. No big deal – especially since you have to write the code to be multithreaded in the first place – but it would be nice if it was all a bit easier, right?!? Well now it is!!! 😎
The Deco (deco) project allows you to easily create code that takes advantage of parallel processing in Python. You simply do it with decorators!
If you’re new to programming, a decorator is just something that you place in your code next to a function/method/class, etc. definition. For example, the Deco project uses
tags. In Python you apply a decorator immediately before a function/method, etc. You can see some examples in the README.md file (that is shown to you by default) in this project: https://github.com/alex-sherman/deco (same link as above)
I expect you will be able to see some examples and some of my code very soon, as well. 😇
Bonus Linux tip:
How to Isolate a CPU (core) and dedicate it to a specific task
To run a task on core 3 of a Raspberry Pi, or other Debian-based distro, including Ubuntu, simply add:
to the end of /boot/cmdline.txt. (There can be only one line in this file.)
And then run:
taskset -c 3 <your task here>
BTW, if you get a chance, please check out my new blog! http://lelandgreen.com
And if you like it, will you please share it around? 😎👍