If there's a resource hog than it's probably related to doing IO which is pretty much unavoidable. Perhaps it's possible to execute the code in a subprocess and call `ionice` but beyond that not much you can do about it.