How do I catch a select timeout error from Python try except

asked 2019-08-01 13:52:37 -0600

phellipex gravatar image

updated 2019-08-02 12:23:31 -0600

Hello everyone.

I'm working with a USB camera that sometimes fails with the infamous select timeout issue. I'm working on fixing that but for now I just want to manually shutdown and restart the camera port whenever this happens.

So here is my question: how can I catch a select timeout error? I'm thinking something along these lines:

cap = cv2.VideoCapture(0)

while(True):
try:
    success, frame = cap.read()
except SelectTimeoutException:
    restart_port()
    ...

The problem is that either OpenCV is not actually raising a Python error but rather printing directly or there is already a Try/Except block somewhere in the cv2 source catching the exception.

I'd appreciate any help.

edit retag flag offensive close merge delete

Comments

it's unlikeley, that you can do anythng from python there (opencv is a c++ library, not a python one)

you did not show us the error msg, or your build information, but those errors are mostly coming from 3rd party / gstreamer libs, so don't expect pathon exceptions here.

berak gravatar imageberak ( 2019-08-01 14:42:08 -0600 )edit

No errors are coming out, just select timeout repeatedly printed to the console. Then my program attempts to run operations on the frame variable and erors out because there is no such frame. That's all.

Also, I'm using opencv-python 3.4.2.17

phellipex gravatar imagephellipex ( 2019-08-01 15:03:59 -0600 )edit