티스토리 뷰

Programming Languages/Python

Python Timer with Thread

sw편한세상 2011.11.20 01:08
import threading
import time

class ExTimer(threading.Thread):

	def __init__(self): 
		threading.Thread.__init__(self) 
		# default delay set.. 
		self.delay = 1
		self.state = True 
		self.handler = None

	def setDelay(self, delay): 
		self.delay = delay

	def run(self): 
		while self.state: 
				time.sleep( self.delay ) 
				if self.handler != None: 
						self.handler()

	def end(self): 
		self.state = False				   

	def setHandler(self, handler): 
		self.handler = handler

def timerHandler():
	print "Timer"

th = ExTimer()
th.setHandler(timerHandler)
th.setDelay(0.5)
th.start()



Python 매력이 넘치네~
댓글
댓글쓰기 폼
공지사항
Total
374,447
Today
17
Yesterday
47
링크
«   2018/12   »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
글 보관함