Forums

query.all()

Hi there

I have a funny problem with the function query.all() After 3 days it stops working and then, if I delete all rows in the table, it starts working again. I know im missing something but I cant figur out what it is.

Hope somebody can help - the function is below

@app.route('/show_all')   
def show_all():
    return render_template('show_all.html', all_temp = bear.query.order_by(bear.times.desc()).limit(50).all())

[edit by admin: code formatting]

What do you see in your error log when it stops working and what do you mean by "stops working"?

There is nothing in the error log I mean that the data from the table doesn't get 'pulled' so you can view it in the show_all template So when I login on the page or refresh it, the data from the table is not refreshed as it normally would be

What about your server log? Sometimes (depending on your how you've configured your web app) errors may be logged there.

Nothing in the server log either

That seems really unlikely.

Have you tried printing some info to stderr to see what might be going on? If you can determine a little more about what is going on with that query, you can probably find a path to follow.

Well okay but nevertheless it's happening But thanks anyway I'm gonna try some other forums for help :)

And Yes I have tried to log the query - nothing

Try taking the "limit(50)." out?

It looks like you're using Flask -- do you get more logging if you enable debug mode with

app.config["DEBUG"] = True

...?

So it happen again at 11:59 pm last night The problem right now is, that all my error logs is gone as well I dont get it

Hi there, we archive your log files after they reach a certain size. You can find them all in /var/log (if you refresh your web tab you'll find we've added a link).

Maybe there's something in the old logs that will give an indication of what's going on?

Thanks :-)

So according to my errorlog the server loses its mysql connection. I have google around and I think I have a problem with the connectionspools. I dont understand what I'm doing wrong - because I'm closing the connection everytime but thats not enhough. What am I missing ?

We set a 5-minute timeout on connections: https://help.pythonanywhere.com/pages/UsingMySQL/.

If you can figure out how to set a timeout on your connection pool, set it to some value just under 300 seconds?

I can do that - im not a complete idiot ;-) Im gonna try that

Thanks

Let us know how you get on :-)

It keeps happening - im out of ideas Anybody?

  • is there any pattern to what time of day it happens?
  • do you have any logging that can tell you whether your queries are taking a particularly long time?

No, there is not a particular time. But I do get ERROR 2006 (HY000): MySQL server has gone away when I log onto my mysql server after it stopped working. But the strange thing is that I can write to the database at all times but the server fails or die on query get requests So what im trying to say is that I get an "ERROR 2006 (HY000): MySQL server has gone away for outgoing data/query_all after a periode of time but I can instance = model(user_id, hulla_,datetime.now()) session.add(instance) session.commit() session.close() at all times Hope it makes sence - English is my second language :-)

That looks like sqlalchemy code -- just to double-check you have set the pool_recycle value? https://help.pythonanywhere.com/pages/UsingSQLAlchemywithMySQL