G
20

Tried a simple for loop to update some user profiles, ended up crashing my database instead

So I'm a total beginner at this coding thing, been learning Python for about 2 months now. I was working on a little project to clean up a list of fake user profiles for practice. Thought I'd write a quick for loop to change all the 'status' fields to 'active' (you know, just a simple update). What I didn't realize is that I had a bug in my loop condition, and it just kept looping without ever stopping. The database I was using on my local machine (SQLite) ended up getting hammered with thousands of update queries in under 30 seconds. It locked up completely, and I had to kill the process and restart everything. The lesson? Always add a safety counter or break condition in your loops when you're testing. I never thought a tiny mistake like forgetting to increment a variable could cause such a mess. Has anyone else accidentally frozen their whole dev environment with a runaway loop?
2 comments

Log in to join the discussion

Log In
2 Comments
nora54
nora5411d ago
Saw a dev on YouTube describe this exact SQLite meltdown scenario.
4
aaron_wilson17
Yeah @nora54 that was probably the same guy who saved my butt a few months back. I ran into this exact issue with a side project and had to rewrite half my queries because the default behavior caught me off guard. That video broke down the locking problem perfectly and it was wild seeing it happen in real time.
6