Sometimes I can't get the camera image with Jetson nano

I ran the code to move the camera in Jetson nano.

import cv2

GST_STR = ‘nvarguscamerasrc
! video/x-raw(memory:NVMM), width=1280, height=720, format=(string)NV12, framerate=(fraction)30/1
! nvvidconv ! video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx
! videoconvert
! appsink’
WINDOW_NAME = ‘Camera Test’

def main():
cap = cv2.VideoCapture(GST_STR, cv2.CAP_GSTREAMER)

while True:
    ret, img = cap.read()
    if ret != True:
        break

    cv2.imshow(WINDOW_NAME, img)

    key = cv2.waitKey(10)
    if key == 27: # ESC 
        break

if name == “main”:
main()

I was able to shoot the camera image.

However, sometimes I can’t get the camera image.
Do you know why this happens?
By the way, sometimes a reboot will fix the problem, but it’s not absolute.