-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread4.py
More file actions
31 lines (29 loc) · 700 Bytes
/
thread4.py
File metadata and controls
31 lines (29 loc) · 700 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
import threading
import time
import Queue
class Producer(threading.Thread):
def __init__(self,t_name):
threading.Thread.__init__(self,name=t_name)
def run(self):
for count in range(10):
queue.put(count)
print "prodece %s"%(count)
time.sleep(0.1)
class Customer(threading.Thread):
def __init__(self,t_name):
threading.Thread.__init__(self,name=t_name)
def run(self):
for x in range(10):
count = queue.get()
print "custome %s"%(count)
time.sleep(0.2)
queue = Queue.Queue()
def main():
producer = Producer("producer")
customer = Customer("customer")
producer.start()
print "start producer"
customer.start()
print "start customer"
if __name__ == "__main__":
main()