A number of Arduinos are reset when you open the serial port which in turn activates the bootloader. On those Arduinos, the bootloader waits for an upload or times out after a few seconds.
You don't mention which Arduino you're using; so the above might not be relevant. And you don't show your Arduino code.
Some ideas are in these two related topics by Robin2
Note:
I'm not a Python programmer