OpenCV-Python VideoCapture.read() does not return False when rtsp connection is interrupted

I am trying to calculate possible situations when working with cameras, one of which is not being able to connect to the camera or the camera being unexpectedly disconnected. When that happens cv2.videocapture(rtsp) gets stuck here, it doesn’t return False or any error, it causes my program to freeze. Is there any way I can get a value when the camera cannot be connected or the camera is unexpectedly disconnected? thank you

your best bet is to go around OpenCV and use the corresponding libraries yourself.

Did you use exceptions in your code? To avoid headaches just use your camera SDK. Usually camera sdk’s provide callbacks to the device connection & disconnection.