title: Skip loop if a function is taking too long?
body: <p>I have Python code which is taking too long, and I would like to stop and skip execution of this function if it takes longer than a few seconds.</p>
  <p>For example, the function I want to time is:</p>
  <pre><code>batch_xs, batch_ys = train_loadbatch_from_lists(batch_size)
  </code></pre>
  <p>In some instances this function call takes too long, and I would like to cancel it.</p>
  <p>I'm looking for something like this:</p>
  <pre><code>if time for batch_xs, batch_ys = train_loadbatch_from_lists(batch_size) &gt; 20 seconds:
      then skip
  </code></pre>
  <p>with reference to <a href="https://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish">this post</a>.</p>
  <p>I would like to know how I would call the function again if timeout occurs.</p>
  <p>For instance</p>
  <pre><code>@timeout(15)
  def abcd(hello):
  #some def 
  </code></pre>
  <p>I would like to call the function again if it crosses the timer.</p>