Good morning! Recently I bought an Arduino board to make sort of \"light control\" in my room. Here is the code of the firmware I wrote:
int control = 0;
int
My guess is it has something to with the environment.
import os
print os.environ['PS1']
From a script that will not be set. (And maybe something else too.)
tty's will buffer differently depending on whether or not they think the terminal is interactive. That should be the only difference between the way your two methods work. A lot applications decide this on whether or not PS1 (your terminal prompt) is set. If you set this in you environment manually it may start behaving the same way as it does interactively.
Also, I would call the call the pyserial flush command manually in your script. (And this would be the preferred way to do it. Instead of masquerading as an interactive terminal.)