Nvargus-daemon fails when using multiple sensors on Jetson Nano

Hmmm, interesting, I tried testing one of the cameras and noticed that it would hang even when only one was connected. I swapped it for another with the same sensor.

Now it works, but when I try to use both in a python application, such as

from threading import Thread
import time
import logging
import cv2

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

class VidCam:

    def __init__(self):
        self.caps = []
        self.running = True
        self.cap_thread = None

    def gstreamer_pipeline(self, _id):
        return (
            "nvarguscamerasrc sensor-id=%d ! "
            "video/x-raw(memory:NVMM), "
            "width=(int)%d, height=(int)%d, "
            "format=(string)NV12, framerate=(fraction)%d/1 ! "
            "nvvidconv flip-method=%d ! "
            "video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
            "videoconvert ! "
            "video/x-raw, format=(string)BGR ! appsink" #drop=True max-buffers=5
            % (
                _id,
                1280,
                720,
                120,
                2,
                1280,
                720,
            )
        )

    def cap_frame(self):
        self.running = True
        start_time = time.time()
        count = 0
        for cam_idx in range(2):
            self.caps.append(cv2.VideoCapture(self.gstreamer_pipeline(cam_idx),
                    cv2.CAP_GSTREAMER))
        while self.running:
            for cam_idx in range(2):
                if self.caps[cam_idx].isOpened():
                    ret,img = self.caps[cam_idx].read()
                    if not ret:
                        print("No return for camera %d" % (cam_idx))
                        self.running = False
                        break
                else:
                    print("Camera %d not opened" % (cam_idx))
            count += 1
            if (count % 1000) == 0:
                logger.debug("Pitstop")
            if time.time()-start_time > 600.0:
                logger.info("10 min mark, 1 min break")
                for cam_idx in range(2):
                    self.caps[cam_idx].release()
                time.sleep(60)
                for cam_idx in range(2):
                    self.caps[cam_idx].open(self.gstreamer_pipeline(cam_idx),
                    cv2.CAP_GSTREAMER)
                start_time = time.time()
        end_time = time.time()
        print("Captured %d frames in %.2f secs --> %.2f fps" % (count,
            end_time-start_time,count/(end_time-start_time)))


    def begin_capture(self):
        self.cap_thread = Thread(target=self.cap_frame,args=())
        self.cap_thread.start()

    def halt(self):
        self.running = False
        self.cap_thread.join()
        for cam_idx in range(2):
        	self.caps[cam_idx].release()

if __name__ == '__main__':
    cam = VidCam()
    print("Beginning capture...")
    cam.begin_capture()
    time.sleep(3600)
    print("Stopping capture")
    cam.halt()

It crashes when calling cap.release(), in a way that I need to restart the nvargus-daemon to be able to use the camera again. I does not report anything on dmesg, just crashes with

GST_ARGUS: Cleaning up
Segmentation fault (core dumped)

It does not crash every time, but crashes often.

I am using the .so provided in Errors starting 6 nvarguscamerasrc pipelines in R32.5.0 - #6 by cliff.hofman