title: Timeout (and skip) a block of code inside a python iteration
body: <p>How can I skip and continue when a step of a loop takes too long?</p>
  <p>Below are a few desirable interfaces I'd like:</p>
  <pre class="lang-py prettyprint-override"><code>for x in some_collection:
      with Timeout(2.5):  # time out after 2.5 seconds
          do_something(x)
  </code></pre>
  <p>Would be nice (and even better -- but might be harder):</p>
  <pre class="lang-py prettyprint-override"><code>with TimeoutLoopStep(2.5):  # time out after 2.5 seconds
      for x in some_collection:
          do_something(x)
  </code></pre>
  <p>Possibly an equivalent <code>timeout_loop_step</code> decorator to consume iterators in that manner:</p>
  <pre class="lang-py prettyprint-override"><code>timeout_loop_step(2.5)(map(do_something, some_collection))
  </code></pre>
  <p>--- Addendum (edit) to dispel some ambiguity ---</p>
  <p>What I'm looking for is a context manager and/or decorator that will interrupt the processing of a step of an iteration if it lasts too long.</p>
  <p>Most APIs that talk to a remote system (e.g. DBs) provide some sort of <code>timeout</code> parameter that means <em>&quot;do this, but if you exceed <code>timeout</code> trying, just phorgetaboutit and move on to the next item...&quot;</em></p>
  <p>But if I'm not offered such control, I'd like to achieve it, externally, with a reusable context manager or decorator.</p>