OK, I think I've tracked down what's going on. The CPU usage after you stopped the task wasn't from the task itself -- it was from a Jupyter notebook. They consume CPU at a rate of about a second a minute, even when idle, and one has been running in your account. You can shut it down totally by using the "Running processes" table on the "Consoles" page to kill all processes called things like "jupyter", "kernel" or "sudospawner". That would explain about 90% of the CPU usage that's showing up against your account right now.
Regarding the high CPU usage when you were testing it, your code is like this (I've changed a couple of function/variable to protect your privacy):
time_to_wait_to_do_something = 30
#...
while True:
if round(time.time()) % time_to_wait_to_do_something == 0:
do_the_thing()
time.sleep(1)
That is essentially using up CPU power as fast as it can most of the time. To see why, consider what happens if the test fails -- it just goes immediately around the loop again, without sleeping. So most of the time it's in a busy wait -- that is, every 30 seconds it sleeps for a second, but the rest of the time it might as well be
Which will consume CPU at a rate of one second per second.
If you move the time.sleep(1)
outside the if
statement, that should sort out the task's CPU usage.
Finally, regarding getting it to actually do what you want it to do :-) I'd suggest adding in a bit of logging to see exactly what's happening in that loop. Combined with the moved time.sleep()
statement, something like this should give you an idea about what's going on:
time_to_wait_to_do_something = 30
#...
print("Starting loop....")
while True:
if round(time.time()) % time_to_wait_to_do_something == 0:
print("Doing the thing")
do_the_thing()
time.sleep(1)