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

  • Home
  • SEARCH
  • 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 7040197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:53:22+00:00 2026-05-28T01:53:22+00:00

I have a Flask web application using SQLAlchemy with MySQL, and I have set

  • 0

I have a Flask web application using SQLAlchemy with MySQL, and I have set up a scopedsession(). I also have a teardown_request handler that calls session.remove() after every request is finished. For some odd reason, if no requests are made on the web app for a day or more, the app gets “Operationalerror: MySQL Server has gone away”.

In my debugging mission, I looked at SHOW PROCESSLIST and saw the following:

39817253 | sqladmin | my_host | kb_dev   | Sleep   |  174 |

The 174 is the number of seconds the connection from my application has been “sleeping”. It keeps counting up if the application doesn’t make another request.

It seems like my application holds on to the connection to MySQL even after my request has finished! And there is usually only one process no matter how many requests I make with my application, simultaneously or not.

My question is if it is normal for the connection to be “sleeping” this long? I’m pretty sure the extended sleeping is causing MySQL to cut the connection after a certain timeout which in turn is causing the “OperationalError: Mysql has gone away” error.

  • 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-05-28T01:53:23+00:00Added an answer on May 28, 2026 at 1:53 am

    SQLAlchemy’s default behavior is to pool connections within the Engine:

    http://www.sqlalchemy.org/docs/core/engines.html

    http://www.sqlalchemy.org/docs/core/pooling.html

    As far as the disconnect overnight thing, this is a known MySQL behavior, SQLAlchemy provides the pool_recycle flag to work around it. Here are many links which describe it:

    http://www.sqlalchemy.org/docs/dialects/mysql.html#connection-timeouts

    http://www.sqlalchemy.org/docs/core/pooling.html#setting-pool-recycle

    http://www.sqlalchemy.org/docs/core/engines.html#sqlalchemy.create_engine (pool_recycle)

    http://www.sqlalchemy.org/trac/wiki/FAQ#MySQLserverhasgoneaway

    Blog post from just a few days ago:

    http://douglatornell.ca/blog/2012/01/08/staying-alive/

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

Sidebar

Related Questions

I am working on an web application using flask, postgresql and sqlalchemy and coding
I have written a small webapp using the flask framework that involves plotting using
I have a web application that currently uses Flash. That application allows the user
I have a flash (flex) web application and when it first loads the cursos
I have a flash player that has a set of songs loaded via an
I have a Flash application that is hosted from within a Drupal page. Some
I have an ASP.NET 2.0 application that is working fine in our local environment.
We have to create the demo for our web application.Our application is a J2EE
I have developed an image uploading application that uses Flash to load an image,
I have many SWF file those I have included in my web page using

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.