title: Prevent infinite loop on update function that updates itself?
body: <p>I'm using Drupal 7 with Commerce, although that doesn't really matter I think.</p>
  
  <p>There's a hook (function) <code>hook_entity_update()</code> that is called when an entity (my shopping cart) is updated.</p>
  
  <p>I want to recalculate my shipping in this hook, the issue is that it saves the entity again once the shipping is recalculated and so it calls the hook again, getting me stuck in an infinite loop.</p>
  
  <p>What would be the best way to solve something like this?</p>
  
  <p>I was thinking of using a simple $_SESSION variable, like $_SESSION['updating'] and set it to TRUE at the start of the hook, then set it to FALSE again at the end of the hook and prevent the function from running with a return at the start if the variable is set to true? I'm not sure if this is a good solution?</p>
  
  <p>Using a session variable because it's a form and the function seems to be called multiple times when submitting.
  Not sure if a regular variable would work?</p>
  
  <p>One issue I'm already running into is that the variable is somehow not reset at the end of the function and so the function is never called again ...</p>