MCPcopy Create free account
hub / github.com/VITA-MLLM/VITA-Audio / ThreadSafeQueue

Class ThreadSafeQueue

web/queue.py:86–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84
85
86class ThreadSafeQueue:
87 def __init__(self):
88 """
89 Initialize the ThreadSafeQueue with an empty queue and a lock for thread safety.
90
91 Parameters:
92 - None
93
94 Returns:
95 - None
96 """
97 self._queue = queue.Queue()
98 self._lock = threading.Lock()
99
100 def put(self, item):
101 """
102 Add an item to the queue in a thread-safe manner.
103
104 Parameters:
105 - item (any): The item to be added to the queue.
106
107 Returns:
108 - None
109 """
110 with self._lock:
111 self._queue.put(item)
112
113 def get(self):
114 """
115 Retrieve an item from the queue in a thread-safe manner.
116
117 Parameters:
118 - None
119
120 Returns:
121 - any or None: The retrieved item if the queue is not empty, otherwise None.
122 """
123 with self._lock:
124 if not self._queue.empty():
125 return self._queue.get()
126 else:
127 return None
128
129 def clear(self):
130 """
131 Clear the queue in a thread-safe manner.
132
133 Parameters:
134 - None
135
136 Returns:
137 - None
138 """
139 with self._lock:
140 while not self._queue.empty():
141 self._queue.get()
142
143 def is_empty(self):

Callers 1

resetMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected