AN: how to get update event from sockets?
A node should not react to changes of the value of a socket. What you are trying to do is not possible. You cannot create an event handler yourself that is executed when the eg the boolean input socket changes.

Also run2 is not a property of the node. This is why self.run2 raises an error. The final value of run2 is passed into the execute function. It my differ from the value of the socket (when the value comes from another node via a link).

The propertyChanged and executionCodeChanged event handlers are mostly used by the Auto Execution system. When propertyChanged is called the tree will execute (only if Property Changed is activated in the Auto Execution panel).

The executionCodeChanged event on the other side triggers a new generation of the execution code. Furthermore the new execution code will be executed if Tree Changed is activated in the Auto Execution panel.

The keepNodeState decorator stores the current values and links to a node in the beginning of the function execution and sets them back on the newly created sockets when the real function ends. This makes it much easier to update sockets without having to care about all the details every time.

When you create/move/remove sockets the treeChanged event is called automatically. It does pretty much the same as executionCodeChanged. This is why I don't have to call executionCodeChanged again after I changed the sockets.