from threading import Thread import time class happyfoo(Thread): def __init__(self, threadname): self.count = 5 Thread.__init__(self, name=threadname) def run(self): while self.count > 0: self.makenoise() self.count -= 1 time.sleep(.1) # trivial delay for demonstrative purposes def makenoise(self): """ do lots of hard work. I should probably be locked! """ print "%s: I should be locked, hopefully someone else does that for me!" % self.getName() # Pretend like we're doing something. time.sleep(2)