title: Timeout uncontrolled overridden function in Python
body: <p>There have been some questions discussing this but none have the set of constraints that I have so maybe someone will come with a good idea.</p>
  
  <p>Basically I need to set-up a timeout for a Python function under the following constraints:</p>
  
  <ol>
  <li><p>Cross-platform (i.e. no signal.ALARM)</p></li>
  <li><p>Not Python 3 (I can assume Python >= 2.7.9)</p></li>
  <li><p>Only the function needs to be timed-out, can't just exit the entire program.</p></li>
  <li><p>I have absolutely no control over the called function, i.e. it's a callback using an abstract interface (using derived classes and overrides). Other people will be writing these callback functions and the assumption is that they're idiots.</p></li>
  </ol>
  
  <p>Example code:</p>
  
  <pre><code>class AbstractInterface(Object):
      def Callback(self):
          # This will be overridden by derived classes.
          # Assume the implementation cannot be controlled or modified.
          pass
  
  ...
  
  def RunCallbacks(listofcallbacks):
      # This is function I can control and modify
      for cb in listofcallbacks:
          # The following call should not be allowed to execute
          # for more than X seconds. If it does, the callback should
          # be terminated but not the entire iteration
          cb.Callback()
  </code></pre>
  
  <p>Any ideas will be greatly appreciated.</p>