Why setup() is triggered each time I open a serial connection?

Hi all,

I use Pyserial to communicate with Arduino UNO (my host is a Linux). But I found each time I open a serial connection, the setup() in Arduino executes. I thought setup() is executed only once when Arduino is boot (plug in USB providing power). Am I wrong?

My setup() looks like:
int setupPin = 12;
void setup() {
Serial.begin(9600);
Serial.write("OK");
pinMode(setupPin, OUTPUT);
digitalWrite(setupPin, HIGH);
delay(100);
digitalWrite(setupPin, LOW);
delay(100);
digitalWrite(setupPin, HIGH);
delay(100);
digitalWrite(setupPin, LOW);
}

I put a LED on pin 12. Each time my host use Pyserial to open a serial connection, I see the LED blink twice.

How can I avoid triggering setup() for each serial connection? Arduino takes about 2 seconds to complete setup...

I thought setup() is executed only once when Arduino is boot (plug in USB providing power). Am I wrong?

No. Opening the serial port resets the Arduino, though.

How can I avoid triggering setup() for each serial connection? Arduino takes about 2 seconds to complete setup...

Permanently or temporarily?

http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection