Just out of curiosity, could you put in a short sleep? You’re hitting your server continuously. Maybe your server"s contents haven’t actually changed. Also, do you have verification from an outside source that new records have been added to the table? Maybe query from a second process which just asks for COUNT(*)?
Are transactions involving the new insertions being properly ended? (Sorry, should have thought of this before. It’s been ages since I’ve done any real database work.) Can you post the code which performs the inserts?
My advice, as already somebody else recommended, is TO SET A SLEEP in the loop. Probably for 1 second or very closed to 1 sec. When you run code in shell loop you launch Python interpreter every loop step which “give it some time to breeze” between loop steps… In pure Python code the query between loop steps is too fast for database to update (being a more lower process becausr involve write operations).