title: Real-time interrupts in Python
body: <p>I have a Python 2.7 program running an infinite while loop and I want to incorporate a timer interrupt.
  What I aim to do is to set off a timer at some point in the loop, and when 5 seconds have elapsed I want the code to branch to a specific part of the while loop.</p>
  
  <p>What I have been doing so far is the following:
  in each iteration of the while loop I am checking how much time has elapsed when I reach that point in the code using</p>
  
  <pre><code>time.clock()
  </code></pre>
  
  <p>and if the difference exceeds 5 I run the chunk of code I mean to run</p>
  
  <p>However that way 7 seconds might pass before I evaluate the time, it will be >5sec but I want to go there <strong>exactly</strong> when 5 seconds pass</p>
  
  <p>Also, I need this to work for more than 1 counter (possibly up to a 100) but I do not want the interrupts to interrupt each other. Using Timer did not work either.</p>
  
  <p>I know this can be done using timer interrupts in assembly but how can I do that in python?</p>