Web App not retrieving shelved data correctly after wakes from repl sleep
LucasGagne (0)


This is becoming a larger project (by my standards), so I apologize in advance to those trying to help. I am an amateur making my first substantial web app. I'm learning a ton from this project!

I am using python, flask, and shelve to save user data as they respond in the various web forms. That data is saved using shelve and later processed and used to change the various user information (class attributes like person.cash) when I run the "Next Turn" function/route.

The app is kind of like a more realistic version of the turn based game 'Life'. The app works well (so far) and I'm working to improve it and use it in my classroom as a financial literacy tool. Definitely learning a lot of ways to organize and make things more efficient.

My problem is that whenever I wake the app from repl sleep (this problem does NOT occur in any other instance) I suddenly cannot pull the class instance data correctly from my shelve file (gamedata). Specifically, some of my attributes are accessible after I load it from shelve, but some raise an AttributeError. It's as if half of my class instance data was lost. In one repl "session" this problem does NOT occur. I can take a hundred turns in a row and the app handles the data properly. But if I wait a few hours and come back, the app will not run without me resetting the game and starting from the beginning.

I am not sure if the problem is in the logic/syntax of my code (my method of saving and loading from gamedata), my understanding of shelve and its limitations, my understanding of replit and its limitations, or something else. It's difficult to troubleshoot as I have to wait for the repl to fall asleep before my trial and error attempts.

Thanks in advance for any help!

You are viewing a single comment. View All
ArchieMaclean (613)

It's not your code. repl.it uses free Heroku hosting to host websites for free, and part of the free thing is that it goes to sleep after 1/2 hour of inactivity.

To fix this you would have to use either a paid Heroku account or another paid host. This would require you to do some research to find out how to use them - you may need to download the files off repl.it and push them to your host with git.

LucasGagne (0)

@ArchieMaclean Thanks for the quick response and the details behind the repl sleep. Could you explain to me how the sleep affects my game data? I use shelve to store the game data into a file (like a text file). Shouldn't that persist beyond the sleep? And why does only a quarter of my data persist?

Thanks for your time.