-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path33.py
More file actions
30 lines (24 loc) · 627 Bytes
/
33.py
File metadata and controls
30 lines (24 loc) · 627 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
from threading import Thread
import time
import random
from queue import *
queue = Queue(10)
class ProducerThread(Thread):
def run(self):
nums = range(5)
global queue
while True:
num = random.choice(nums)
queue.put(num)
print("Produced", num)
time.sleep(random.random())
class ConsumerThread(Thread):
def run(self):
global queue
while True:
num = queue.get()
queue.task_done()
print("Consumed", num)
time.sleep(random.random())
ProducerThread().start()
ConsumerThread().start()