-
Notifications
You must be signed in to change notification settings - Fork 26
/
Queue_video1and2_finalversion.py
114 lines (50 loc) · 1.28 KB
/
Queue_video1and2_finalversion.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# -*- coding: utf-8 -*-
#Using threading with queue
import queue
import threading
import time
def putting_thread(q):
while True:
print('starting thread')
time.sleep(10)
q.put(5)
print('put something')
##
#
#
#
q = queue.Queue()
t = threading.Thread(target = putting_thread, args = (q,),daemon = True)
t.start()
q.put(5)
print(q.get())
print('first item gotten')
print(q.get())
print('finished')
#intializing a variable to q.get()
x =q.get()
print(x)
#difference between LIFO and FIFO
import queue
q = queue.Queue()
for i in range(5):
q.put(i)
while not q.empty():
print(q.get(), end = ' ')
print('\n')
import queue
q = queue.LifoQueue()
for i in range(5):
q.put(i)
while not q.empty():
print(q.get(), end = ' ')
# priority queue
import queue
import time
q = queue.PriorityQueue()
q.put((1, 'Priority 1'))
q.put((3, 'Prioirty 3'))
q.put((4 ,'Priority 4'))
q.put((2 ,'Priority 2'))
for i in range(q.qsize()):
print(q.get()[1])