Can't finish Python Deepstream app properly with Ctrl+C

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU)
• DeepStream Version
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only)
Driver Version: 460.32.03
• Issue Type( questions, new requirements, bugs)

I have a Python Deepstream app and I want it to end properly when pressed Ctrl+C.

My pipeline has the following elements (less important elements are skipped, just to have an idea):

source -> streammux -> tee -> nvinfer -> nvvideoconvert -> nvdosd -> filesink
                        |---> filesink

My main code is:

self.loop =, False)
GLib.unix_signal_add(-100, 2, self.handle_sigint, None)
self.bus = self.gst_pipeline.get_bus()
self.bus.connect("message", self.bus_message_handler)

The bus message handler function:

def bus_message_handler(self, bus, message: Gst.Message) -> bool:
    t = message.type"****************** Message received {t}")
    if t == Gst.MessageType.EOS:
        logger.success("End of Stream")
    elif t == Gst.MessageType.WARNING:
        err, debug = message.parse_warning()
        logger.warning(f"{err}: {debug}")
    elif t == Gst.MessageType.ERROR:
        err, debug = message.parse_error()
        logger.error(f"{err}: {debug}")
        self.gst_error = f"{err}: {debug}"
    return True

And finally the sigint handler function:

def handle_sigint(self, user_data=None):"SIGINT detected. Sending EOS...")
    self.bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.EOS)

The expected behaviour would be:

Run -> Ctrl+C pressed -> Print "SIGINT detected. Sending EOS..." -> Print "End of Stream"

But “End of Stream” is never printed out. Why the EOS message is not being received by the bus_message_handler? How is the proper way of implementing this Ctrl+C functionality to end properly the app? Currently the app finishes without receiving the EOS message, so the saved videos are corrupt.


Ok, so the issue is handle_sigint sent an Event but bus_message_handler didn’t reveive it, right?

Yes. It looks like the bus_message_handler didn’t receive this message…


In the handle_sigint function, self.bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.EOS) is called after sending the EOS event with self.gst_pipeline.send_event(Gst.Event.new_eos()). Looking at the gstreamer documentation, it seems that the EOS message is popped from the bus before it can reach the message handler. Instead, you can try passing the popped message directly into your message handler function as follows:

def handle_sigint(self, user_data=None):"SIGINT detected. Sending EOS...")


self.bus_message_handler(self.bus, self.bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.EOS))

Doing so should result in your expected behaviour on pressing ctrl + c. Hope this helps!