-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.py
More file actions
33 lines (22 loc) · 690 Bytes
/
proxy.py
File metadata and controls
33 lines (22 loc) · 690 Bytes
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
""" Proxy is used to postpone the creation of object """
import time
class Producer:
def meet(self):
print('Producer has time to meet you now!')
class Proxy:
def __init__(self) -> None:
self.busy = 0
self.producer = None
def meet_producer(self):
print("Checking if the producer is availabole..")
# Delay for 2 seconds
time.sleep(2)
if self.busy == 0:
self.producer = Producer()
return self.producer.meet()
print('Producer is busy!')
p = Proxy()
# p.meet_producer()
# Change the state of proxy
p.busy = 1
p.meet_producer()