title: Timeout a function (windows)?
body: <p>I am trying to implement timeout for a particular function. I have checked many of the questions in SE and couldn't find any solution which fits my problem, because:</p>
  
  <ol>
  <li>I am running python in Windows</li>
  <li>Timeout is applied on a python function which I don't have control on, i.e. it is defined in an already designed module.</li>
  <li>The python function is not a subprocess</li>
  </ol>
  
  <p>I am having a already designed custom module (say <code>MyModule</code>) developed for particular tasks, and there are functions defined in it. One of the function (say <code>MyFunc</code>) has a tendency to run forever because of external factors, and I just don't want the python script to hang.</p>
  
  <p>I am planning to add a timeout feature, as said below pseudocode:</p>
  
  <pre><code>import MyModule
  
  set_timeout(T)
  MyResult=MyModule.MyFunc()
  
  #Come to this part of script after execution of MyFunc() or after T seconds (the latter on priority)
  if Timeout occurred:
      print 'MyFunc did not execute completely'
  else:
      print 'MyFunc completed'
  </code></pre>
  
  <p>But I am not sure which module can be used to achieve this on python. Note that I am a newbie, and all the scripts I have written are directly based on SE Answers or Python Documentation.</p>