Python Forum
scheduled job only runs once
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scheduled job only runs once
#1
import time
import schedule

def job():
    import asdf_1 # "asdf_1" is a .py file that runs fine on its own

schedule.every().day.at("13:00").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)
the above code only runs once at the first 13:00 mark. it doesn't run the next day or the day after or ever. why? i know crontab is a more versatile (and perhaps reliable) scheduling module. but at this point i'm more curious why the "schedule" module doesn't work in this case.
Reply
#2
Quote:why?
def job():
    import asdf_1 
All that you code do is importing module. Python's modules are imported only once per process.
Reply
#3
(Aug-19-2019, 06:53 AM)fishhook Wrote:
Quote:why?
def job():
    import asdf_1 
All that you code do is importing module. Python's modules are imported only once per process.

would love to know the alternative... other than execfile of course...
Reply
#4
refactor asdf_1?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(Aug-19-2019, 06:55 AM)Stan2292 Wrote: would love to know the alternative... other than execfile of course...
importlib.reload(packagename)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Importing a function from another file runs the old lines also dedesssse 6 382 Jul-06-2021, 07:04 PM
Last Post: deanhystad
  How to create an Excel app that runs Python? felipe0216 3 839 May-31-2020, 01:19 AM
Last Post: ibutun
  Python Program Runs in Pycharm but not in Terminal Vbhardwaj2383 2 1,495 Apr-06-2020, 04:41 PM
Last Post: Vbhardwaj2383
  How to execute code WHILE a function runs t4keheart 4 1,042 Jan-27-2020, 01:47 PM
Last Post: t4keheart
  Scheduler runs but then fails marciokoko 2 2,109 Jan-19-2017, 12:02 AM
Last Post: marciokoko

Forum Jump:

User Panel Messages

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