update stop function
This commit is contained in:
parent
58f0dd75ac
commit
c85407c074
@ -325,31 +325,29 @@ class MultiDongle:
|
|||||||
# print("Threads stopped.")
|
# print("Threads stopped.")
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""
|
"""Improved stop method with better cleanup"""
|
||||||
Stop inference threads cleanly
|
if self._stop_event.is_set():
|
||||||
"""
|
return # Already stopping
|
||||||
|
|
||||||
print("Stopping threads...")
|
print("Stopping threads...")
|
||||||
self._stop_event.set()
|
self._stop_event.set()
|
||||||
|
|
||||||
# Unblock send thread if waiting on queue
|
# Clear queues to unblock threads
|
||||||
try:
|
while not self._input_queue.empty():
|
||||||
self._input_queue.put(None, timeout=1.0)
|
try:
|
||||||
except:
|
self._input_queue.get_nowait()
|
||||||
pass
|
except queue.Empty:
|
||||||
|
break
|
||||||
|
|
||||||
# Join threads with reasonable timeout
|
# Signal send thread to wake up
|
||||||
threads = [
|
self._input_queue.put(None)
|
||||||
(self._send_thread, "Send thread"),
|
|
||||||
(self._receive_thread, "Receive thread")
|
|
||||||
]
|
|
||||||
|
|
||||||
for thread, name in threads:
|
# Join threads with timeout
|
||||||
|
for thread, name in [(self._send_thread, "Send"), (self._receive_thread, "Receive")]:
|
||||||
if thread and thread.is_alive():
|
if thread and thread.is_alive():
|
||||||
thread.join(timeout=3.0)
|
thread.join(timeout=2.0)
|
||||||
if thread.is_alive():
|
if thread.is_alive():
|
||||||
print(f"Warning: {name} did not stop within timeout")
|
print(f"Warning: {name} thread didn't stop cleanly")
|
||||||
|
|
||||||
print("All threads stopped")
|
|
||||||
|
|
||||||
def put_input(self, image: Union[str, np.ndarray], format: str, target_size: Tuple[int, int] = None):
|
def put_input(self, image: Union[str, np.ndarray], format: str, target_size: Tuple[int, int] = None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user