Public feed #889293

threading

public text v1 · immutable
Raw Edit
·published 2008-02-02 20:46 UTC
rendered paste body
 1 #!/usr/bin/env python
 2
 3 import time
 4 import threading
 5
 6 from packet import Packet
 7
 8 class Test(threading.Thread):
 9     def __init__(self, o):
10         super(Test, self).__init__()
11         self.o = o
12
13     def run(self):
14         self.exit = False
15         while not self.exit:
16             time.sleep(1)
17             print self.o.do()
18
19         # program has stopped
20
21     def quit(self):
22         self.exit = True
23
24 if __name__ == "__main__":
25     class o(object):
26         def __init__(self):
27             test = Test(self)
28             print "start thread"
29             test.start()
30             count = 0
31             while count < 10:
32                 print "no exit"
33                 count += 1
34                 time.sleep(1)
35             test.quit()
36
37         def do(self):
38             return "this is a test"
39     o()
40 # vim :set ts=4