title: How to fix this basic example of threading in Python
body: <p>I am trying to teach myself how to use threading in Python. I have come up with the basic problem of trying to interrupt a function that would continue printing the square of a number forever after only 10 seconds. I used this website as an example: <a href="http://zulko.github.io/blog/2013/09/19/a-basic-example-of-threads-synchronization-in-python/" rel="nofollow noreferrer">http://zulko.github.io/blog/2013/09/19/a-basic-example-of-threads-synchronization-in-python/</a>. The code that I have now does not work as intended and I'm wondering if any of you could help me fix it so I can understand threading better. Thank you in advance!</p>
  
  <pre><code>import threading
  import time
  
  def square(x):
      while 1==1:
          time.sleep(5)
          y=x*x
          print y
  
  def alarm():
      time.sleep(10)
      go_off.set()
  
  
  def go():
      go_off= threading.Event()
      squaring_thread = threading.Thread(target=square, args = (go_off))
      squaring_thread.start()
      square(5)
  go()
  </code></pre>