title: Stop code after time period
body: <p>I would like to call <code>foo(n)</code> but stop it if it runs for more than 10 seconds.  What's a good way to do this?</p>
  
  <p>I can see that I could in theory modify <code>foo</code> itself to periodically check how long it has been running for but I would prefer not to do that.</p>