AareGUI: Smoothen exit from GUI by adding timeout on ZeroMQ
This commit is contained in:
@@ -28,7 +28,7 @@ class VideoThread(QThread):
|
||||
self.session = requests.Session()
|
||||
|
||||
# Set connection timeout and read timeout
|
||||
timeout = (5, 30) # (connect_timeout, read_timeout)
|
||||
timeout = (1, 3) # (connect_timeout, read_timeout)
|
||||
|
||||
try:
|
||||
# Start streaming
|
||||
@@ -124,10 +124,8 @@ class VideoThread(QThread):
|
||||
|
||||
def stop(self):
|
||||
self.running = False
|
||||
print("Video thread stop requested")
|
||||
if self.session:
|
||||
self.session.close()
|
||||
self.quit()
|
||||
print("Video thread stopped. Exiting...")
|
||||
self.wait()
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class SampleCameraThread(QThread):
|
||||
context = zmq.Context()
|
||||
self.__socket = context.socket(zmq.SUB)
|
||||
self.__socket.setsockopt(zmq.SUBSCRIBE, b"")
|
||||
self.__socket.setsockopt(zmq.RCVTIMEO, 500)
|
||||
self.__socket.connect(zmq_url)
|
||||
|
||||
self.running = True
|
||||
@@ -40,6 +41,8 @@ class SampleCameraThread(QThread):
|
||||
self.camera_image.emit(QPixmap.fromImage(qimage))
|
||||
else:
|
||||
print("Sample camera image has wrong dimensions")
|
||||
except zmq.Again: # Timeout occurred
|
||||
continue # Check self.running again
|
||||
except Exception as e:
|
||||
print(f"Error in sample camera thread {e}")
|
||||
|
||||
@@ -50,5 +53,4 @@ class SampleCameraThread(QThread):
|
||||
if self.__socket:
|
||||
self.__socket.close()
|
||||
self.quit()
|
||||
print("Camera thread stopped. Exiting...")
|
||||
self.wait()
|
||||
|
||||
Reference in New Issue
Block a user