-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy_final.py
More file actions
executable file
·45 lines (33 loc) · 1.03 KB
/
proxy_final.py
File metadata and controls
executable file
·45 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import time
class Producer:
"""Define the 'resource-intensive' object to instantiate!"""
def produce(self):
print("Producer is working hard!")
def meet(self):
print("Producer has time to meet you now!")
class Proxy:
""""Define the 'relatively less resource-intensive' proxy to instantiate as a middleman"""
def __init__(self):
self.occupied = 'No'
self.producer = None
def produce(self):
"""Check if Producer is available"""
print("Artist checking if Producer is available ...")
if self.occupied == 'No':
#If the producer is available, create a producer object!
self.producer = Producer()
time.sleep(2)
#Make the prodcuer meet the guest!
self.producer.meet()
else:
#Otherwise, don't instantiate a producer
time.sleep(2)
print("Producer is busy!")
#Instantiate a Proxy
p = Proxy()
#Make the proxy: Artist produce until Producer is available
p.produce()
#Change the state to 'occupied'
p.occupied = 'Yes'
#Make the Producer produce
p.produce()