Arduino and Python under Windows. Slow serial??

Hi, I need to receive some input from a python software, to get the arduino switch some pin to HIGH. The point is that it works only if I send the caracters every 2 seconds (one caracter every 2 sec) and I can't understand if I implemented bad code for the arduino, or for py.

Here's the arduino sketch:

/*
 * Accensione RME e Amplificatori
 * Per accendere gli amplificatori inviare "s 0 1" e per spegnerli "s 0 0"
 * Per accendere la scheda audio inviare "s 1 1" e per spegnerli "s 1 0"
 * Connettere i rele' per gli ampli al pin 3 e quello per la scheda audio al 2
 */

int relayPinRME = 2;     // RME Relay is connected to pin 2
int relayPinAMP = 3;     // AMP Relay is connected to pin 3
char AMP='0'; // Ho messo il carattere 0 e non il valore 0
char RME='1'; // Attenzione alla differenza tra caratteri e interi!
char val;

void setup() {
  pinMode(relayPinRME, OUTPUT);    // Set the RME pin as output
  pinMode(relayPinAMP, OUTPUT);    // Set the AMP pin as output
  Serial.begin(9600);
}

char gentlyRead() {
  while (1) {
    if (Serial.available()>0) return Serial.read();
  }
}

void loop(){
  char c;
  char apparato;
  char stato;
  // send data only when you receive data:
  if (Serial.available() > 0) {
  // read the incoming byte:
  val = Serial.read();

    if (val == 's') {     // legge due caratteri inviati dopo s, separati da uno spazio
      while ((c=gentlyRead())==' ');
      //Serial.print(c,DEC);
      apparato=c;
      while ((c=gentlyRead())==' ');
      //Serial.print(c,DEC);
      stato=c;

        // esegue le operazioni indicate
        if (apparato == AMP && stato=='0'){
          Serial.println("Spengo Amplificatori...");
          digitalWrite(relayPinAMP, LOW);
        }
        if (apparato == AMP && stato=='1'){
          Serial.println("Accendo Amplificatori...");
          digitalWrite(relayPinAMP, HIGH);
        }
        if (apparato == RME && stato=='0'){
          Serial.println("Spengo Rme...");
          digitalWrite(relayPinRME, LOW);
        }
        if (apparato == RME && stato=='1'){
          Serial.println("Accendo Rme...");
          digitalWrite(relayPinRME, HIGH);
        }
      }
    }

  // arduino libero

}

And there, the python code

import os,sys,time

import win32api

from win32file import * # The base COM port and file IO functions.

from win32event import * # We use events and the WaitFor[Multiple]Objects functions.

import win32con # constants.

from getopt import getopt,GetoptError



import msvcrt



def usage():

    print "error - refer to source code and arduino for correct usage."



def main():

    try:

        opts, args = getopt(sys.argv[1:], "s")

    except GetoptError, err:

        # print help information and exit:

        print str(err) # will print something like "option -a not recognized"

        usage()

        sys.exit(2)

    for o, a in opts:

        if o == "-s":

            apparecchio,stato=list(args[0])



            port = "COM6"

            handle = CreateFile(port,

                                           win32con.GENERIC_READ | win32con.GENERIC_WRITE,

                                           0, # exclusive access

                                           None, # no security

                                           win32con.OPEN_EXISTING,

                                           win32con.FILE_ATTRIBUTE_NORMAL | win32con.FILE_FLAG_OVERLAPPED,

                                           None)

            # Tell the port we want a notification on each char.

            SetCommMask(handle, EV_RXCHAR)

            # Setup a 4k buffer

            SetupComm(handle, 4096, 4096)

            # Remove anything that was there

            PurgeComm(handle, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR )

            # Setup for overlapped IO.

            timeouts = 0xFFFFFFFF, 0, 1000, 0, 1000

            SetCommTimeouts(handle, (200,0,1000,0,1000))

            # Setup the connection info.

            dcb = GetCommState( handle )

            dcb.BaudRate = 9600

            dcb.ByteSize = 8

            dcb.Parity = NOPARITY

            dcb.StopBits = ONESTOPBIT

            SetCommState(handle, dcb)



            eventStop = CreateEvent(None, 0, 0, None)



            overlapped = OVERLAPPED()

            overlapped.hEvent = CreateEvent(None, 1, 0, None)

            """

            try:

                while 1:

                    ch = msvcrt.getch()

                    if ord(ch)==3:

                        break

                    WriteFile(handle, ch, overlapped)

                    print ch,ord(ch)

                    # Wait for the write to complete.

                    WaitForSingleObject(overlapped.hEvent, INFINITE)

            finally:

                SetEvent(eventStop)

            """



            for ch in ' s 1 1':

                WriteFile(handle, ch, overlapped)

                print ch,ord(ch)

                #time.sleep(2)

                WaitForSingleObject(overlapped.hEvent, INFINITE)



        else:

            assert False, "unhandled option"

    # ...



if __name__ == "__main__":

    main()

I have forced some variable in the code just for testing, and I can make it work under linux, with python, where I can use the serial as a file. But I need it working in windows too...

Thanks, Federico