Python thread can not be cancelled
<p>I have a python thread which should display a message every second, while the rest of the script continues running. But the <code>timer.cancel</code> function does not work, as it still keeps running even after the main loop have been terminated:</p>

<pre><code>from threading import *
import time
import sys

a = 0

def x():
    while(True):
        global a
        print
        print 'Beep', a
        print
        time.sleep(1)   # wait 1 second      

t = Timer(1.0, x)       # create thread
t.start()               # start thread

while True:
    a = a + 1
    print a
    time.sleep(0.1)

    if a &gt; 30:    
        t.cancel()
    if a &gt; 50:
        sys.exit()
</code></pre>

<p>What am I doing wrong ?</p>