proxy.py 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import time
  2. class SalesManager:
  3. def work(self):
  4. print("Sales Manager working...")
  5. def talk(self):
  6. print("Sales Manager ready to talk")
  7. class Proxy:
  8. def __init__(self):
  9. self.busy = 'No'
  10. self.sales = None
  11. def work (self):
  12. print("Proxy checking for Sales Manager availability")
  13. if self.busy == 'Yes':
  14. self.sales = SalesManager()
  15. time.sleep(2);
  16. self.sales.talk()
  17. else:
  18. time.sleep(2);
  19. print("Sales Manager is busy")
  20. if __name__ == '__main__':
  21. p = Proxy()
  22. p.work()
  23. p.busy = 'Yes'
  24. p.work()