I don't see your bug yet, unless you send more than 10 characters between angle brackets.
But there is a bug in such a case: if you send more than 9 characters you'll overflow the inData buffer and overwrite index, which is the sort of thing that can lead to the weird behavior you're seeing.
It's best to check to see if there's room in a buffer before adding a character to it.
Now I get it. You want the Python program to reconnect to the Arduino when it's unplugged and then plugged back in.
I've never got unplug/replug detection working in Python. It would go something like this: You'd need to detect the closing of the port (and the disappearing of its com port or device file), wait for its reappearance, and re-open it as you currently do.