Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:17:11+00:00 2026-06-11T03:17:11+00:00

Python: 2.7.3 Flask: 0.9 Hi, I want to make car simulator using Apscheduler .

  • 0
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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:17:13+00:00Added an answer on June 11, 2026 at 3:17 am

    g is probably a threading.local(). Different threads see different values in it.

    g.db is probably assigned a new db connection per request. No current request – no connection.

    You could create db connection in move_all_cars() or pass it explicitly as a parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to cache Python/flask responses with memcached. I then want to serve the
Im using the python framework flask with sqlalchemy. My many-to-many looks like this: collections_questions
With Python web application frameworks such as Flask, webapp2 and Pyramid, how can each
I'm creating a blog (and the rest of a website) using Python and Flask
I'm generating an HTML page via Python, using the Flask framework to receive messages
I have 2 questions. So i am making a python program that will backup
I am writing my website's backend using Flask and Python 2.7, and have run
I see that we can try Flask (the python micro framework from the browser,
I'm developing a multi-player game in Python with a Flask frontend, and I'm using
I'm using Python Flask to run Python for web through FCGI with nginx. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.