question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't start the scheduled jobs properly

See original GitHub issue

Hi there,

I’m trying to use schedule to runs two simple task in the background on a small project. And I don’t know how to start it properly.

My code:

schedule.py

import threading, time, schedule

def run_continuously(interval=1):
    cease_continuous_run = threading.Event()

    class ScheduleThread(threading.Thread):
        @classmethod
        def run(cls):
            while not cease_continuous_run.is_set():
                schedule.run_pending()
                time.sleep(interval)
        continuous_thread = ScheduleThread()
        continuous_thread.start()
        return cease_continuous_run

def sunday():
    now = datetime.now().strftime('%Y-%m-%d')
    if now == 'any chosen date':
        do my thing ...
    else:
        print('print a message')

def hour_job():
    now = datetime.now().strftime('%Y-%m-%d')
    if now == 'another chosen date':
        do my other thing ...
    else:
        print('print another message')

schedule.every().sunday.at("14:00").do(sunday)
schedule.every(2).hours.do(hour_job)

cease_continuous_run = run_continuously()
time.sleep(1)
stop_run_continuously.set() # even if I comment this line the jobs do not start

# and when I did an attempt from outside like:

from diary.alert.schedule import run_continuously
run_continuously()

# or with sunday() or hour_job()  not the three at same time of course! each job runs twice O,O

Just one more thing. I did noticed when I comment the line

stop_run_continuously.set()

and comment the external trigger

from diary.alert.schedule import run_continuously
run_continuously()

save both files start the server then uncomment the external trigger and save the file the jobs run like they supposed to. Perfectly in harmony with the desired schedule.

I do thank in advance for any help!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

5reactions
SijmenHuizengacommented, May 21, 2021

Ah I see, it is getting better and better! The indentation is almost perfect now.

Yes, this is a good way to start a background thread that runs scheduled jobs 👍

1reaction
DoomCreaturecommented, May 21, 2021

Ah I see, it is getting better and better! The indentation is almost perfect now.

Yes, this is a good way to start a background thread that runs scheduled jobs +1

Thank you for your help @SijmenHuizenga

Read more comments on GitHub >

github_iconTop Results From Across the Web

Task Scheduler not running, triggering or starting programs
Check and start Task Scheduler service · Change the Service configuration · Start Task Scheduler using Command Prompt · Run System File Checker ......
Read more >
Task Scheduler not Running: 5 Methods to Enable it Again
2. Manually start the Task Scheduler · Press Windows + R , then type services.msc and hit Enter . · Right-click on the...
Read more >
How to Fix Windows Task Scheduler Not Running on ...
Open Task Scheduler. Double-click the task that will not run. Go to the Conditions tab. Uncheck the 'Start the task only if the...
Read more >
Windows Task Schedule not launching application
Hi, I am stuck with a very basic thing, the Windows Task Schedule to run an application recurring. Initially I thought it's my...
Read more >
Windows Task Scheduler does not start task at next run time
My fix was simple... I had already manually ran the scheduled task, but I created the scheduled task for the intent of using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found