I have a script which does a lot of computational work and is very resource intensive. When I am running the script (which typically takes several hours to complete), I am almost unable to use my machine, because it grinds to a halt.
I remember in the old days of VB programming, there was a yield()
statement, which forced a memory hogging routine to be nice and hand over some CPU cycles to other processes.
My question is, is there a similar construct in Python which allows me to write scripts that play nicely with other processes on my machine?
Typical script below ....
# import required libs
if __name__ == '__main__':
init()
do_some_expensive_calcs() # need to periodically 'yield' to other processes here - how do I do it?