title: right way to run some code with timeout in Python
body: <p>I looked online and found some SO discussing and ActiveState recipes for running some code with a timeout. It looks there are some common approaches:</p>
  
  <ul>
  <li>Use thread that run the code, and <code>join</code> it with timeout. If timeout elapsed - kill the thread. This is not directly supported in Python (used private <code>_Thread__stop</code> function) so it is <strong>bad practice</strong></li>
  <li>Use <code>signal.SIGALRM</code> - but this approach <strong>not working on Windows</strong>!</li>
  <li>Use subprocess with timeout - but this is <strong>too heavy</strong> - what if I want to start interruptible task often, I don't want fire process for each!</li>
  </ul>
  
  <p>So, what is <strong>the right way</strong>? I'm not asking about workarounds (eg use Twisted and async IO), but actual way to solve actual problem - I have some function and I want to run it only with some timeout. If timeout elapsed, I want control back. And I want it to work on Linux and Windows.</p>