Boolean doesn't keep its value

Hey there,
I am trying to set up a communication between a python script on my pc and my Arduino.
I'm already able to turn a LED on and off with two keyboard shortcuts.
But I encountered a problem when l tried to toggle the LED with one shortcut
because the boolean saving the current led state ('led') is always false when serialEvent() starts.

Here's my Arduino code:

unsigned int led_pin = 13;//the pin of the integrated led
boolean led = false;//the boolean for the led state
String msg = "";

void setup() {
 Serial.begin(9600);
 pinMode(led_pin,OUTPUT);
 digitalWrite(led_pin,false);
}

void serialEvent() {
 while(Serial.available()){
   char inChar= (char) Serial.read();//add all received chars to a string
   if(inChar=='\n'){//python finished sending
     msg+='\0';//null-terminate the string
     if(msg=="led_on"){
       led=true;
       digitalWrite(led_pin,led);
       Serial.println(msg);
       msg="";
     }else if(msg=="led_off"){
       Serial.println("led_off");
       led=false;
       digitalWrite(led_pin,led);      
       Serial.println(msg);
       msg="";
     }else if(msg=="led"){ //MY PROBLEM IS HERE:
       Serial.print(led);//print the value of led
       led= !led;//change it
       Serial.println(led);//print it again; it should have changed
       digitalWrite(led_pin,led);//toggle the LED
       msg="";
     }
   }else{
     msg+=inChar;
   }
 } 
}

void loop(){}

And here's the python script although it doesn't seem relevant for me:

import pythoncom,pyHook,sys,logging,serial,time
port="COM5"

def OnKeyboardEvent(event):#handles keyboard events
   print("Key: ",event.Key)#print the key pressed
   ctrl=pyHook.GetKeyState(pyHook.HookConstants().VKeyToID('VK_CONTROL'))#true if control is down
   if event.Key == "L" and ctrl:#Ctrl+L: turn LED on
       try:
           arduino= serial.Serial(port,9600,timeout=.1)
           time.sleep(3)
           arduino.write(b"led_on"+b'\n')
           data = arduino.readline().decode().rstrip('\n')
           if data: 
               print(data)
       except serial.serialutil.SerialException:
           print("ERROR")
       return False
   elif event.Key=="K" and ctrl:#Ctrl+K: turn LED off
       try:
           arduino= serial.Serial(port,9600,timeout=.1)
           time.sleep(3)
           arduino.write(b"led_off"+b'\n')
           data = arduino.readline().decode().rstrip('\n')
           if data: 
               print(data)
       except serial.serialutil.SerialException:
           print("ERROR")
       return False
   elif event.Key=="J" and ctrl:#Ctrl+J: toggle LED
       try:
           arduino= serial.Serial(port,9600,timeout=.1)#open the port
           time.sleep(3)#give it some time
           arduino.write(b"led"+b'\n')#write 'led\n' to the port
           data = arduino.readline().decode().rstrip('\n')#get the line the arduino answers
           if data:
               print(data)#print it
       except serial.serialutil.SerialException:
           print("ERROR")
       return False
   return True

hm=pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()

The console output in python if I press Ctrl+J(the shortcut for toggling the LED) twice:

Key:  Lcontrol
Key:  J
01

Key:  J
01

The first numer after the key is always the value of 'led' at the start of serialEvent() and the second is the value at the end of it. As you see the value is 0(false) the second time Ctrl+J is pressed, which it shouldn't be because it was 1(true) after it was pressed the first time.

Does anybody have an idea on how to fix this issue?
I've been trying to find my mistake for several hours now and I can't find it.
I also tested this code with two different boards.

Every time that python opens the serial port the Arduino is reset.

UKHeliBob:
Every time that python opens the serial port the Arduino is reset.

Thank you, I'm going to try opening the port only once.

EDIt:
Thank you really much, it works now.
But I have another question:
Why does opening a serial port reset the Arduino.
It doesn't make any sense to me, because you're able to call Serial.begin() wich opens a serial port without resetting the Arduino.

GreenSmurf:
Thank you, I'm going to try opening the port only once.

If you find that too difficult (and assuming you're using an Uno), there is a "hack" where you can put a 10μF capacitor between Reset and Ground which will prevent the pulse from the PC actually causing it to reset. Just make sure it's not permanent because it makes reprogramming tricky.

So the arduino can tell whether you want serial communication or re-programming.

GreenSmurf:
It doesn't make any sense to me, because you're able to call Serial.begin() wich opens a serial port without resetting the Arduino.

That does not open a serial port. It just sets the hardware to receive and transmit over the Tx and Rx.

The PC does open the port and when it does it toggles the DTR line causing the Arduino to reset. This is done so the IDE has a way of resetting the Arduino (needed to start programming).