title: How to cancel a setInterval in python?
body: <p>I am using this code to call a function <code>doSomething</code> every 3 seconds. but I want that when <code>numeroPeticiones== 3</code>, stop doing it. I have looked for many examples, but none works. In my case, my function continues to be executed eternally, even though the condition of <code>numeroPeticiones== 3</code> is fulfilled. how can I solve that? </p>
  
  <pre><code>import threading
  from threading import Timer
  numeroPeticiones=0
  
  def doSomething():
      global numeroPeticiones
      numeroPeticiones=numeroPeticiones+1
      print ("hello, world",numeroPeticiones)
      if numeroPeticiones == 3:
          print("cancel")
          t.cancel()
  
  def set_interval(func, sec): 
      def func_wrapper():
          set_interval(func, sec) 
          func()  
      t = threading.Timer(sec, func_wrapper)
      t.start()
      return t
  </code></pre>