segfault if I restart the camera in same script

I have jetbot installed and I have been making progress. Now I am making a python3 script that takes camera pictures. I discovered a problem:

If I initialize an instance of the class, and then call .restart() on that instance, there would be a segfault

If I call .stop() and .start(), I also get a segfault

The last lines of output looks like

GST_ARGUS: Running with following settings:
   Camera index = 0
   Camera mode  = 0
   Output Stream W = 3280 H = 2464
   seconds to Run    = 0
   Frame Rate = 21.000000
Segmentation fault (core dumped)

it SHOULD look like (but doesn’t):

GST_ARGUS: Running with following settings:
   Camera index = 0
   Camera mode  = 0
   Output Stream W = 3280 H = 2464
   seconds to Run    = 0
   Frame Rate = 21.000000
GST_ARGUS: PowerService: requested_clock_Hz=37126320
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.

(I am doing all this from the python3 interactive console, no code to post)

I am not skilled enough to identify whether this is a problem with cv2, or with python threading, or with something else, sorry. I don’t even know how to get the core dump right now.

The camera can be used again if I simply quit out of python3 and get back into python3

The camera is a IMX219, a Raspberry Pi cam v2, with 160 degree FOV

What is the problem and can this problem be fixed?


I’ll admit my goal here is a bit over-engineered. I have a jetbot but with bigger motors, and a microcontroller pretending to be the motorhat over I2C. One difference is I programmed in a “safety” so I can shutdown the motors and it will ignore subsequent commands from rogue scripts. The script I am writing now is a background service that checks for a DualShock4 controller and uses it as a remote kill-switch. (I am paranoid, yes, but I’ve had 7 stitches from a home built home programmed muilticopter before)

It also handles simply remotely moving the robot. I also coded in a camera shutter button, plus a button where it will continuously take pictures. All image files are tagged with the controller state for training purposes. Example: if I drive it to follow a line on the ground, all the images will contain whether I told it to go left or right.

I don’t want this script to hog the camera, but I want the script to run all the time and auto-start to keep the robot “safe”.

Yes I understand there are several workarounds but I’d like to see if the segfault can be fixed.


The image of the camera is catched by gstreamer.and wrapped with a PYTHON interface.
Which may not support well with start, restart action.

Once you got the error, you can try bellow command to recover from.

sudo systemctl restart nvargus-daemon.service

Please see here:

I segfaulted it the same way. Apparently you need to poll for the Argus daemon to come back up before reopening the camera, but Dusty_nv recommends just opening the camera once and all it’s resources will be automatically freed on program close.

Watch the above thread and later today I plan to post something that will attempt to poll the daemon before restarting.

I did something really hacky… I made another python script that runs the camera, and the first script uses subprocess.Popen() to run the second script, and uses .kill() to stop the camera

This works, and I can start and shutdown the camera repeatedly without a problem, and while the camera is not active, other scripts are able to use the camera