Python Forum
Cancelling previous schedule
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cancelling previous schedule
#1
Hi,

Just starting out with Python and am using VSCode to schedule a simple task so am using the following to get started:
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()
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:
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)
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
Reply


Messages In This Thread
Cancelling previous schedule - by cosmarchy - Sep-14-2021, 07:48 PM
RE: Cancelling previous schedule - by snippsat - Sep-15-2021, 11:26 AM
RE: Cancelling previous schedule - by Larz60+ - Sep-15-2021, 04:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Hosting a script on a VPS, and on a schedule? oldguy 0 2,989 Mar-13-2021, 02:46 AM
Last Post: oldguy
  Cancelling 'open directory' leading to crash Fairbz_ 1 2,209 May-08-2020, 03:14 PM
Last Post: DPaul
  something i noticed about the "schedule" module Stan2292 1 1,795 Aug-30-2019, 06:04 AM
Last Post: buran
  How to schedule Jupyter Notebooks with Papermill wendysling 0 2,529 Jun-11-2019, 05:53 PM
Last Post: wendysling
  schedule module conundrum wgovideo 11 4,419 May-29-2019, 06:39 PM
Last Post: wgovideo
  I got a problem with python schedule darktitan 2 3,531 Sep-22-2018, 12:49 PM
Last Post: darktitan
  Schedule with other processing RValentim 7 4,031 Jul-10-2018, 12:57 PM
Last Post: RValentim
  How to convert Schedule to APScheduler module? penguin9 2 3,805 May-03-2018, 12:44 PM
Last Post: penguin9
  Creating a schedule program ndplokkaar 4 4,006 Nov-23-2017, 04:21 PM
Last Post: ndplokkaar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020