import threading import time import itertools class Foo threading Thre

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import threading
import time
import itertools
class Foo(threading.Thread):
def __init__(self, *args, **kwargs):
self.stop_flag = False
super(Foo, self).__init__(*args, **kwargs)
def stop(self):
self.stop_flag = True
def run(self):
iter = itertools.count()
while not self.stop_flag:
print iter.next()
time.sleep(1)
t = Foo()
t.start()
time.sleep(5)
t.stop()