2

I am trying to schedule a job in python using the APScheduler package. This answer looked great, but it's snytax is out of date. I went to user guide for the current version 3, but I cannot find a basic example where I can pass a datetime object to the scheduler like in the linked answer.

from datetime import date
from apscheduler.schedulers.background import BackgroundScheduler as Scheduler
from datetime import datetime

# Start the scheduler
sched = Scheduler()
sched.start()

# Define the function that is to be executed
def my_job(text):
    print text

#Schedule job
job = sched.add_job(my_job, next_run_time = datetime(2015, 5, 11, 1, 05, 5), args = ['Hello World!'])

This yields the error: No handlers could be found for logger "apscheduler.executors.default".

Community
  • 1
  • 1
Michael
  • 13,244
  • 23
  • 67
  • 115
  • 1
    The code above worked for me... Looks like the error you get is related to logging module... see this answer and question http://stackoverflow.com/a/17551794/1478277 – Shahram May 17 '15 at 00:41
  • How about this? https://apscheduler.readthedocs.org/en/latest/modules/triggers/date.html#module-apscheduler.triggers.date – Alex Grönholm May 17 '15 at 10:19
  • Note also that with a script like this, your main thread will end as soon as you've scheduled that job, thus terminating the process. – Alex Grönholm May 17 '15 at 10:19
  • @AlexGrönholm So if I added an infinite loop at the end of the script to keep it open the job would excecute at the specified time? What's the alternative? – Michael May 17 '15 at 16:20
  • Use BlockingScheduler. That's the very purpose it was made for. – Alex Grönholm May 18 '15 at 16:24

0 Answers0