title: python interrupt a command if it takes longer than it should
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/492519/timeout-on-a-python-function-call">Timeout on a Python function call</a><br>
    <a href="https://stackoverflow.com/questions/11901328/how-to-timeout-function-in-python-timout-less-than-a-second">How to timeout function in python, timout less than a second</a>  </p>
  </blockquote>
  
  
  
  <p>I am running a function within a for loop, such as the following:</p>
  
  <pre><code>for element in my_list:
      my_function(element)
  </code></pre>
  
  <p>for some reason, some elements may lead the function into very long processing time (maybe even some infinite loop that I cannot really trace where it comes from). So I want to add some loop control to skip the current element if its processing for example takes more than 2 seconds. How can this be done?</p>