When using PyMongo, No handlers could be found for logger "apscheduler.scheduler"
<p>The code works fine printing to screen <code>hello</code> every second. This is done using the <code>bar</code> method, which is added to the scheduler as a job.</p>

<p><strong>Problem:</strong> However when the line <code>self.db.animals.insert_one({'name': 'lion'})</code> is added to the <code>bar</code> method, running the script gives an error</p>

<pre><code>No handlers could be found for logger "apscheduler.scheduler"
</code></pre>

<p>and the script stalls. Any idea what happened and how we can solve it?</p>

<pre><code>from apscheduler.schedulers.blocking import BlockingScheduler
import pymongo

class Foo(object):

    def __init__(self, db, interval=1):
        self.interval = interval
        self.db = db
        self.sched = BlockingScheduler()
        self.sched.add_job(self.bar, 'interval', seconds = interval)

    def start(self):
        self.sched.start()

    def stop(self):
        self.sched.shutdown()

    def bar(self):
        print 'hello'
        self.db.animals.insert_one({'name': 'lion'})


client = pymongo.MongoClient("localhost", 27017)
db = client.earth
foo = Foo(db, 0.2)
foo.start()
</code></pre>

<p>That's not an error, but a warning. Python's logging system is trying to tell you that it has no outlet for logging output because you haven't configured it. Try using <code>logging.basicConfig(level=logging.DEBUG)</code>.</p>

python python-2.7 pymongo apscheduler