A simpler solution might be to nice or re-nice your app. If you are running a Unix variant (Linux, *BSD, Mac), try something like this:
nice -n 19 python my_code.py
More info here: https://en.wikipedia.org/wiki/Nice_(Unix)
On Windows, you can try to set the priority via Task Manager (locate the Python process in Processes tab, right-click and select Set Priority).