Python: 2.7.3
Flask: 0.9
Hi, I want to make car simulator using Apscheduler
. Each car has distance
column in the database that will be incremented regularly.
Here's the import part
from __future__ import with_statement
from flask import Flask, request, session, g, redirect, url_for, \
abort, render_template, flash, views
from sqlite3 import dbapi2 as sqlite3
from contextlib import closing
from apscheduler.scheduler import Scheduler
and here's the snippet of the code:
sched = Scheduler()
sched.add_interval_job(moveAllCars, seconds = 5)
sched.start()
def moveAllCars():
print "debug 1"
dbCommand = g.db.execute('SELECT CarID FROM Car')
print "debug 2"
#and so on
I did not write the full code because the error happened right after 'debug 1' with the error message: no handlers could be found for logger "apscheduler.scheduler". Google does not help much.
But the scheduler is still running, printing only 'debug1' every 5 seconds. The error message only come out during the first loop.
Anyone know the solution? Thanks before
[UPDATE]
After using logging
, I found out it is RunTimeError: working outside of request context. Is there any other solution other than using with app.test_request_context
?