Technically you don’t need to wrap the code in an IF statement. Just having an aditional port IN for a Boolean toggle will do the trick. No need to tie in with code and will work on either true or false values, just need to switch once before you run again. This just triggers the Nodes input changed event and adds to the list of nodes to re-execute.
Same goes for custom nodes, chuck an “input” node within the parent node named refresh which will just add a new port to a the custom node but the input node doesn’t need to be connected to anything downstream in the parent node.
@Konrad_K_Sobon’s solution works nicely for nodes that you don’t want to execute every time and only until you want them to, good for exporting or model updating type nodes. So go with his if that’s the functionality you’re after.