Trigger 'cron' do not working in apscheduler 3 while 'interval' works fine

3,774 views
Skip to first unread message

Weiming Zhao

unread,
Apr 12, 2016, 8:58:06 AM4/12/16
to APScheduler

I am trying to use package apscheduler 3.1.0 to run a python job every day at the same time. But it seems do not run the job correctly. In the following simple case, the trigger "interval" can work, but "cron" won't. When run the following code in python 2.7.11, it seems running, but did not print anything.


from apscheduler.schedulers.blocking import BlockingScheduler

def job_function():
    print "Hello World"

sched = BlockingScheduler()
sched.add_job(job_function, 'cron', second = '*/2')
sched.start()

When replacing

sched.add_job(job_function, 'cron', second = '*/2')

to

sched.add_job(job_function, 'interval', seconds = 2), it works fine.

I already update the setuptools to 20.6.7. Does anybody know what is wrong?

Alex Grönholm

unread,
Apr 12, 2016, 9:12:32 AM4/12/16
to apsch...@googlegroups.com
I cannot reproduce your problem. I tried with both Python 2.7 and 3.5 and this script worked fine no matter how many times I ran it. Would you please enable debug logging? Logging setup is done in the example scripts if you need to learn how.

bis...@greensmith.us.com

unread,
Jun 13, 2016, 4:15:47 PM6/13/16
to APScheduler
I have the same issue on windows, python 2.7.10, apscheduler 3.1.0 with the following code:

import logging
import time
from apscheduler.schedulers.background import BackgroundScheduler


def tick():
    print("TICK")

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    scheduler = BackgroundScheduler()
    scheduler.start()
    scheduler.add_job(tick, 'cron', second='*')
    # scheduler.add_job(tick, 'interval', seconds=1)
    time.sleep(10)



The log output for the cron version looks like:

INFO:apscheduler.scheduler:Scheduler started
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:No jobs; waiting until a job is added
INFO:apscheduler.scheduler:Added job "tick" to job store "default"
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:Next wakeup is due at 2016-06-13 16:08:39-04:00 (in 0.702000 seconds)
DEBUG:apscheduler.scheduler:Looking for jobs to run


The working interval version logs out:

INFO:apscheduler.scheduler:Scheduler started
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:No jobs; waiting until a job is added
INFO:apscheduler.scheduler:Added job "tick" to job store "default"
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:Next wakeup is due at 2016-06-13 16:09:06.038000-04:00 (in 0.984000 seconds)
DEBUG:apscheduler.scheduler:Looking for jobs to run
INFO:apscheduler.executors.default:Running job "tick (trigger: interval[0:00:01], next run at: 2016-06-13 16:09:07 EDT)" (scheduled at 2016-06-13 16:09:06.038000-04:00)
TDICKEBUG:apscheduler.scheduler:Next wakeup is due at 2016-06-13 16:09:07.038000-04:00 (in 1.000000 seconds)

INFO:apscheduler.executors.default:Job "tick (trigger: interval[0:00:01], next run at: 2016-06-13 16:09:07 EDT)" executed successfully
DEBUG:apscheduler.scheduler:Looking for jobs to run
INFO:apscheduler.executors.default:Running job "tick (trigger: interval[0:00:01], next run at: 2016-06-13 16:09:07 EDT)" (scheduled at 2016-06-13 16:09:07.038000-04:00)
TDEBUG:apscheduler.scheduler:Next wakeup is due at 2016-06-13 16:09:08.038000-04:00 (in 0.998000 seconds)

...


Anyone have any ideas?

Alex Grönholm

unread,
Jun 13, 2016, 4:21:56 PM6/13/16
to apsch...@googlegroups.com
Can you clarify? What exactly is the issue you're seeing?
-- You received this message because you are subscribed to the Google Groups "APScheduler" group. To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.

bis...@greensmith.us.com

unread,
Jun 13, 2016, 5:16:17 PM6/13/16
to APScheduler
When a new cron job is added, the tick function is never called. If I comment out the cron line and uncomment adding the interval job, the tick function is called as expected. From the logs, it looks like the scheduler never finds the cron job to run it.

Alex Grönholm

unread,
Jun 13, 2016, 5:21:49 PM6/13/16
to apsch...@googlegroups.com
I just happened to commit a fix for the cron trigger, could you try with the latest development version?

bis...@greensmith.us.com

unread,
Jun 14, 2016, 11:29:11 AM6/14/16
to APScheduler
The master branch seems to solve the problem. The only weird issue I saw is that it doesn't work when run from the windows command line, but it does in pycharms, osx, and linux so that's good enough for my dev/deploy environments. Do you think you will publish an updated version to pypi soon? Thanks for the quick responses!

bis...@greensmith.us.com

unread,
Jun 14, 2016, 11:32:19 AM6/14/16
to APScheduler
I see you already published 3.2.0, thanks again!

marcos fernandes

unread,
Jul 8, 2018, 5:50:05 AM7/8/18
to APScheduler
I am trying apscheduler 3.5.1 in python 3.6.3, running from windows. The cron triggered jobs never wake up. They will wake up if run from spyder IDE, but not from windows. Has this ever been fixed? Is there a solution around this to continue using cron triggers in apscheduler for python in windows?

Thanks

alex.g...@nextday.fi

unread,
Jul 8, 2018, 10:47:58 AM7/8/18
to apsch...@googlegroups.com
You say this like you're assuming there's a bug that specifically affects Windows users. To the best of my knowledge, there isn't any. If you can provide a trivial script that triggers a cron related bug on Windows, then please post an issue on the bug tracker.
--

marcos fernandes

unread,
Jul 8, 2018, 11:10:23 AM7/8/18
to APScheduler
I was referring to the earlier post by bis on this thread that had no response.  "The only weird issue I saw is that it doesn't work when run from the windows command line...". Sorrry I wasnt clear. Am running a simple print job. But it wont wake up on windows. Runs perfectly otherwise. Cant find a solution anywhere. Thanks for the answer. 

-------------------------

import datetime as dt
from apscheduler.schedulers.background import BackgroundScheduler
import logging

logging.basicConfig(level=logging.DEBUG)
MKOPENHOUR = 12
MKOPENMIN = 2

def printjob():

    print(dt.datetime.now())
    print ("hello world")
    
sched = BackgroundScheduler()
sched.add_job(printjob, 'cron', hour=MKOPENHOUR, minute=MKOPENMIN)
sched.start()
sched.print_jobs()

-----------------------------------------------

INFO:apscheduler.scheduler:Adding job tentatively -- it will be properly scheduled when the scheduler starts
INFO:apscheduler.scheduler:Added job "printjob" to job store "default"
INFO:apscheduler.scheduler:Scheduler started
DEBUG:apscheduler.scheduler:Looking for jobs to run
Jobstore default:
    printjob (trigger: cron[hour='12', minute='2'], next run at: 2018-07-08 12:02:00 -03)

alex.g...@nextday.fi

unread,
Jul 9, 2018, 3:15:46 AM7/9/18
to apsch...@googlegroups.com
This script will exit as soon as it has printed all the jobs, so it never gets the chance to run printjob().
Reply all
Reply to author
Forward
0 new messages