carbon_ghost
carbon_ghost

Reputation: 1124

No handlers could be found for logger "apscheduler.executors.default"?

I have a python script being run via a nightly job on Heroku. Every once in a while (and lately, a lot more), the script fails to execute due to the below error.

2015-02-25T05:00:02.671242+00:00 app[clock.1]: No handlers could be found for logger "apscheduler.executors.default"

The script is executed using the inbuilt clock method as defined in my Procfile.

clock.py:

import sys
import logging

sys.path.append('main')

from main import main
from apscheduler.schedulers.blocking import BlockingScheduler

sched = BlockingScheduler()

# Executes every night at 5:00am UTC time | 12:00am (midnight) Winston-Salem, NC time
@sched.scheduled_job('cron', hour=5)
def scheduled_job():
    logging.basicConfig()
    main()

sched.start()

I've searched the web and based on the few responses I've read, people say this is a warning as opposed to an error. However, this problem causes the entire script to fail when it does happen. My question is first, is there a fix for this? And secondly, why does this happen sometimes and not always?

Lot's of people said to simply add the following to the script:

import logging
logging.basicConfig()

Which, as you can see, I did but the issue still persists.

Upvotes: 4

Views: 12847

Answers (2)

iChux
iChux

Reputation: 2376

import logging

log = logging.getLogger('apscheduler.executors.default')
log.setLevel(logging.INFO)  # DEBUG

fmt = logging.Formatter('%(levelname)s:%(name)s:%(message)s')
h = logging.StreamHandler()
h.setFormatter(fmt)
log.addHandler(h)

I got mine working with a nice format like this

Upvotes: 10

loopkin
loopkin

Reputation: 11

I had the same situation; the problem may be due to some exceptions in your code that creates some conflict with apscheduler trying to log about them.

try to run your Apscheduler without sys and without logger, but instead just import os; as suggested in the recent documentation.

then review there are no problematic bugs, or un-catched exceptions in your task function (this can be probable) and start your scheduler.

if you can't find the problem in the function then avoid sys, import os and import logger with basic logging.( and it may help you spot your problem)

hope this works also for you.

Upvotes: 1

Related Questions