DeepStream Python Core Dump (import path related)

Pyds apps seem to only work in their current locations. This is my init code for my module using pyds, however on Gst.init() I get a core dump, even though pyds is found and imported (i get no ImportError).

here is my module level init:

import os
import platform
import sys

DEBUG = True
DEEPSTREAM_ROOT = '/opt/nvidia/deepstream/deepstream-4.0'
DEEPSTREAM_BINDINGS_ROOT = os.path.join(
    DEEPSTREAM_ROOT, 'sources/python/bindings')

THIS_DIR = os.path.abspath(os.path.dirname(__file__))
PIE_CONF_TEMPLATE = os.path.join(THIS_DIR, 'pie.conf')

def is_aarch64():
    return True if platform.processor() == 'aarch64' else False

# set up deepstream bindings path
if is_aarch64():
    DEEPSTREAM_BINDINGS_PATH = os.path.join(DEEPSTREAM_BINDINGS_ROOT, 'jetson')
else:
    DEEPSTREAM_BINDINGS_PATH = os.path.join(DEEPSTREAM_BINDINGS_ROOT, 'x86_64')
if DEBUG:
    print(f'DEEPSTREAM_BINDINGS_PATH={DEEPSTREAM_BINDINGS_PATH}')
sys.path.append(DEEPSTREAM_BINDINGS_PATH)

# print sys paths
if DEBUG:
    for path in sys.path:
        print(f'sys.path:{path}')

import mce.install
import mce.bus
import mce.osd
import mce.pipeline
import mce.__main__

(in main, a main function runs Gst.init(), at which point it fails.)

$ mce --verbose sample_720p.h264 
DEEPSTREAM_BINDINGS_PATH=/opt/nvidia/deepstream/deepstream-4.0/sources/python/bindings/jetson
sys.path:/home/anzu/.local/bin
sys.path:/usr/lib/python36.zip
sys.path:/usr/lib/python3.6
sys.path:/usr/lib/python3.6/lib-dynload
sys.path:/home/anzu/.local/lib/python3.6/site-packages
sys.path:/usr/local/lib/python3.6/dist-packages
sys.path:/usr/lib/python3/dist-packages
sys.path:/usr/lib/python3.6/dist-packages
sys.path:/opt/nvidia/deepstream/deepstream-4.0/sources/python/bindings/jetson
DEBUG:mce.__main__:main(sample_720p.h264, /home/anzu/.mce/pie.conf)
DEBUG:mce.__main__:main:GObject.threads_init() complete

(python3:27548): GStreamer-WARNING **: 13:00:05.879: Element factory metadata for 'bin' has no valid long-name field
**
GStreamer:ERROR:gst.c:629:gst_register_core_elements: code should not be reached
Aborted (core dumped)

So, it finds pyds, imports it, but it doesn’t seem to like being called from anywhere else than in a sample location. I can also break the examples if I execute them from a working directory other than their containing ones. eg:

$ cd /opt/nvidia/deepstream/deepstream-4.0/sources/python/apps
$ python3 deepstream-test1/deepstream_test_1.py 
Traceback (most recent call last):
  File "deepstream-test1/deepstream_test_1.py", line 30, in <module>
    from common.is_aarch_64 import is_aarch64
ModuleNotFoundError: No module named 'common'

I was able to get everything working from anywhere by running Gst.init() in my module level init, however that’s before my argument parsing and i’d rather not do that as I’d like to pass some arguments to Gst.init(). Any suggestions?

Hi mdegans,
yes, as you can see in common/is_aarch_64.py and deepstream-test1/deepstream_test_1.py, they are using
relative path, if you want to run them anywhere, you should change the relative path to absolute path.

Admin: Thx for marking the answer. Sorry I forgot. The import path was indeed one problem but what was causing the core dump was related to how I was subclassing Get.Pipeline (not shown).

If anybody runs into the core dump, specifically, I was able to resolve it by initializing gstreamer before importing the code containing my Pipeline subclass (in this case, mce.pipeline). I am assuming this is a gstreamer thing and not Nvidia related. In any case it all works now. Thank you for your help!

Hi mdegans,
Thanks for sharing!