proxy.py 848 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import time
  4. class SalesManager:
  5. def work(self):
  6. print("Sales Manager working...")
  7. def talk(self):
  8. print("Sales Manager ready to talk")
  9. class Proxy:
  10. def __init__(self):
  11. self.busy = 'No'
  12. self.sales = None
  13. def work(self):
  14. print("Proxy checking for Sales Manager availability")
  15. if self.busy == 'No':
  16. self.sales = SalesManager()
  17. time.sleep(2)
  18. self.sales.talk()
  19. else:
  20. time.sleep(2)
  21. print("Sales Manager is busy")
  22. if __name__ == '__main__':
  23. p = Proxy()
  24. p.work()
  25. p.busy = 'Yes'
  26. p.work()
  27. ### OUTPUT ###
  28. # Proxy checking for Sales Manager availability
  29. # Sales Manager ready to talk
  30. # Proxy checking for Sales Manager availability
  31. # Sales Manager is busy