Forums

mysql not working right

ok, i've got flask,mysql,jquery and angluarjs http in my little app. Here's my problem... it's not woring correctly on pythonanywhere? It works perfectly fine on my localhost? Is this because it's a free account or what because i am not inspired to continue using python or paying for this service when i decide to put more apps together. Any Ideas, suggestions, help... inFrame.pythonanywhere.com

ok, it seems to be temperamental - it is working sometimes?

MySQL should be completely reliable -- we haven't seen any outages over the last 24 hours.

One difference between localhost and our system here that you might be seeing is the connection timeout. MySQL always times out idle connections after a certain amount of time. I think the default value is quite high -- maybe eight hours -- but on PythonAnywhere, in order to support lots of users, it's five minutes. (This has the added advantage that if you have a connection management bug, you find out pretty much right away, rather than eight hours later after you've gone to bed...)

If you're using a DB connection manager in your code (say, like SQLAlchemy) then that doesn't really matter -- so long as the connection manager is correctly configured (eg. "app.config["SQLALCHEMY_POOL_RECYCLE"] = 299") then you'll have no problems.

But if you're writing your own SQL code manually, or haven't set the POOL_RECYCLE setting, then you'll get a "OperationalError 2006, 'MySQL server has gone away'" error each time the connection times out.

For manual code, the solution is to close your connections at the end of each view.

Thank you for the repliy.

"For manual code, the solution is to close your connections at the end of each view."

Yes, I forgot to close connection after each call.... my mistake!

Thank you for your informitve help.

inFrame.pythonanywhere.com

Helpful too if anyone has same problem in future, thanks

app.config["SQLALCHEMY_POOL_RECYCLE"] = 299

I did a blog post on building a Flask-based app with SQLAlchemy a while back -- here's a link just in case you might find it useful.

thanks giles nice post. i seem to have to login to pythonanywhere and reload my app all the time to get it to work right? any ideas why that might be? the idea here is you pick a video movie trailer, it plays and on the right of the screen info relating to that video is displayed: year, description, director... so forth. that is the part that's not working correctly on pythonanywhere? It's a call to SQL and Ajax updates the DOM... I'm somewhat stumped by this behavior. Is it to do with the amount of CPU process allocated to each user?

It could be anything. Look in your error and server logs to see if you can work out what's going wrong and start debugging from there.