'ExceptionIgnored error: SIGALRM Timeout handler

I made a custom timeout handler using the SIGALRM signal but very rarely I get an error saying that TimeoutException was 'ignored'.

Timeout handler code:

def timeout_handler(signum, frame):
    raise TimeoutException

signal.signal(signal.SIGALRM, timeout_handler)


camera_stream = ThreadedCamera() # Separate Thread updating image
while True:
    try:
        while True:
            signal.alarm(5) # start 5s timer
            send_image(camera_stream.image) # function is blocked if it doesnt finish within 5 seconds
            signal.alarm(0) # end timer
    except TimeoutException:
        print("timeout")
        time.sleep(5)

Error:

Exception ignored in: <function Context.__del__ at 0x7f93e
Traceback (most recent call last):
File "zmq/sugar/context.py", line 71, in __del__
File "zmq/sugar/context.py", line 190, in term
File "zmq/backend/cython/context.pyx", line 82, in zmq.backend.cyt
File "zmq/backend/cython/checkrc.pxd", line 13, in zmq.backend.cyt
File "camera_client.py", line 22, in timeout_handler
__main__.TimeoutException:

It seems like my try/except statement should catch the TimeouteException considering the alarm is cancelled before I exit the try/except. Is it possible that the camera in the separate thread is somehow catching this error? Any help would be greatly appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source