# L-31 MCS 275 Wed 31 Mar 2010 : fastfood.py # Simulation of fastfood restaurant. from threading import * import time import random class Customer(Thread): """ Customer orders food and eats. """ def __init__(self,t): """ Initializes customer with name t, generates waiting and eating time. """ Thread.__init__(self,name=t) self.wait = random.randint(1,6) self.eat = random.randint(1,6) def run(self): """ Customer waits for order and eats. writes three messages. """ t = self.getName() print t + ' is waiting for %d time units' % self.wait time.sleep(self.wait) print t + ' waited %d time units' % self.wait time.sleep(self.eat) print t + ' ate for %d time units' % self.eat def main(): "defines and starts threads" n = input('give #customers : ') T = [] for i in range(0,n): s = 'name of customer %d : ' % i name = raw_input(' ' + s) T.append(Customer(name)) print "starting the simulation" for t in T: t.start() print "simulation has started" if __name__ == "__main__": main()