Your code looks fine besides your device which is always assigning the CPU, but that shouldn’t be your issue.
Could you run your script in a terminal and see, if you get any errors?
PS: You can add code using three backticks (`). I’ve formatted your code so that it’s easier to read.