Sep-14-2021, 07:48 PM
Hi,
Just starting out with Python and am using VSCode to schedule a simple task so am using the following to get started:
This runs ok and I get "Doing stuff" printed in the terminal but I was struggling to see what the units were - I can see that it was run after 2 somethings (seconds I believe) but I couldn't see from any documentation I could find how you might change this to days or hours etc, so I went looking for some other code and came up across this:
Again this looks like what I need but I cannot run as whenever I do, I get "Doing stuff" printed in the terminal, instead of "I'm working..." which is what I'd expect and leaves me to believe there is something of the previous code still running despite cancelling with ctrl-c. Both of these code examples are in separate files and the one which isn't being worked on is closed.
Is there something going on in the background with schedule which is not being closed down? If so, how can you close off previous jobs when the code exits???
Thanks
Just starting out with Python and am using VSCode to schedule a simple task so am using the following to get started:
1 2 3 4 5 6 7 8 9 10 11 |
import sched import time s = sched.scheduler(time.time, time.sleep) def do_something(sc): print ( "Doing stuff..." ) # do your stuff s.enter( 2 , 1 , do_something, (sc,)) s.enter( 2 , 1 , do_something, (s,)) s.run() |
1 2 3 4 5 6 7 8 9 10 11 12 |
import schedule import time def job(): print ( "I'm working..." ) schedule.canceljob schedule.every( 10 ).seconds.do(job) while 1 : schedule.run_pending() time.sleep( 1 ) |
Is there something going on in the background with schedule which is not being closed down? If so, how can you close off previous jobs when the code exits???
Thanks