import threading import time class Clock(threading.Thread): def __init__(self,sock): super(Clock, self).__init__() self.running = False self.sock=sock def run(self): self.running=True self.handleTime() def handleTime(self): while True: self.sock.send( dict(type='time', time=time.strftime("%H:%M"))) time.sleep(15)