Change your print statements to have flush=True on the end
eg:
print(row, file=sys.stderr, flush=True)
Python buffers output until you access a different stream, so if you have an infinite loop anything sent to stderr after the last input() / print() to stdout won’t be printed.