How to create a DataReader for DCPSParticipant in Python

2 posts / 0 new
Last post
rgs
Offline
Last seen: 1 year 6 months ago
Joined: 07/26/2022
Posts: 7
How to create a DataReader for DCPSParticipant in Python

Hello,

Environment:
debian 11 linux x64
python 3.9.2
rti_connext_dds-6.1.0

 

I'm using the Python api with rti, but it's not well documented or much example code:
How do I create a DataReadear to builtin topics, eg: DCPSParticipant.

I've tried the code below but it crashes when it tries to execute the bind_listener() call (see below).

Any help would be appreciated.
Thanks,

 

import rti.connextdds as dds
import time
import atexit
import sys


# A listener for msg samples
class ParticipantListerner(dds.ParticipantBuiltinTopicData.DataReaderListener):
    def on_data_available(self, reader):
        with reader.take() as samples:
            # Use a filter to process only valid samples
            for sample in filter(lambda s: s.info.valid, samples):
                print(sample.data)
        pass


@atexit.register
def atexit_():
    participant.close()


if __name__ == "__main__":

    participant_qos = dds.QosProvider.default.participant_qos
    participant_qos.participant_name.name = "testrti"
    participant = dds.DomainParticipant(0, participant_qos)
    participant.enable()

    reader = dds.ParticipantBuiltinTopicData.DataReader(participant.find_datareader("DCPSParticipant"))
    reader.bind_listener(ParticipantListerner(), dds.StatusMask.DATA_AVAILABLE)


    while 1==1:
        time.sleep(1)


    sys.exit(0)

 

user@debian:~/rtipy$  cd /home/user/rtipy ; /usr/bin/env /bin/python3 /home/user/.vscode/extensions/ms-python.python-2022.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 45223 -- /home/user/rtipy/try1.py
RTI Connext DDS Research License issued to  ... For non-production use only.
Expires on 31-dec-2023 See www.rti.com for more information.
        Backtrace:
        #4      RTIOsapiThread_onSigsegvHandler Thread.c:? [0x124158]
        #5      __restore_rt sigaction.c:? [0x14140]
        #6      std::vector<rti::topic::ServiceRequest, std::allocator<rti::topic::ServiceRequest> >& pyrti::vector_concat_inplace<rti::topic::ServiceRequest>(std::vector<rti::topic::ServiceRequest, std::allocator<rti::topic::ServiceRequest> >&, std::vector<rti::topic::ServiceRequest, std::allocator<rti::topic::ServiceRequest> >&) ??:? [0x3C16F5]
        #7      rti::sub::LoanedSamples<dds::topic::TParticipantBuiltinTopicData<rti::topic::ParticipantBuiltinTopicDataImpl> >::return_loan() ??:? [0x83C569]
        #8      rti::sub::LoanedSamples<dds::topic::TParticipantBuiltinTopicData<rti::topic::ParticipantBuiltinTopicDataImpl> >::return_loan() ??:? [0x83CCDF]
        #9      std::vector<bool, std::allocator<bool> >::size() const ??:? [0x293DED]
        #10     PySys_GetObject ??:? [0x53F350]
        #11     _PyObject_MakeTpCall ??:? [0x51D89B]
        #12     PyMethod_New ??:? [0x53BF25]
        #13     PyThreadState_Get ??:? [0x51AF55]
        #14     _PyEval_EvalFrameDefault ??:? [0x51975D]
        #15     __pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_bytecode_while_frame_eval_39 :? [0x12743]
        #16     _PyEval_EvalCodeWithName ??:? [0x5106ED]
        #17     _PyEval_EvalCodeWithName ??:? [0x510497]
        #18     PyEval_EvalCode ??:? [0x5F5BE3]
        #19     PyFrozenSet_New ??:? [0x5FA670]
        #20     PyObject_GetIter ??:? [0x5298C4]
        #21     PyThreadState_Get ??:? [0x51AF55]
        #22     _PyEval_EvalFrameDefault ??:? [0x519FC7]
        #23     __pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_bytecode_while_frame_eval_39 :? [0x12743]
        #24     _PyEval_EvalCodeWithName ??:? [0x5106ED]
        #25     _PyFunction_Vectorcall ??:? [0x528D21]
        #26     PyThreadState_Get ??:? [0x51AF55]
        #27     _PyEval_EvalFrameDefault ??:? [0x519FC7]
        #28     __pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_bytecode_while_frame_eval_39 :? [0x12743]
        #29     _PyEval_EvalCodeWithName ??:? [0x5106ED]
        #30     _PyFunction_Vectorcall ??:? [0x528D21]
        #31     PyThreadState_Get ??:? [0x51AF55]
        #32     _PyEval_EvalFrameDefault ??:? [0x518C31]
        #33     __pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_bytecode_while_frame_eval_39 :? [0x12743]
        #34     _PyEval_EvalCodeWithName ??:? [0x5106ED]
        #35     _PyFunction_Vectorcall ??:? [0x528D21]
        #36     PyThreadState_Get ??:? [0x51AF55]
        #37     _PyEval_EvalFrameDefault ??:? [0x518C31]
        #38     _PyFunction_Vectorcall ??:? [0x528B63]
        #39     _PyEval_EvalFrameDefault ??:? [0x511FB5]
        #40     _PyFunction_Vectorcall ??:? [0x528B63]
        #41     _PyEval_EvalFrameDefault ??:? [0x516E76]
        #42     _PyEval_EvalCodeWithName ??:? [0x5106ED]
        #43     _PyEval_EvalCodeWithName ??:? [0x510497]
        #44     PyEval_EvalCode ??:? [0x5F5BE3]
        #45     PyFrozenSet_New ??:? [0x5FA670]
        #46     PyObject_GetIter ??:? [0x5298C4]
        #47     _PyEval_EvalFrameDefault ??:? [0x511FB5]
        #48     _PyEval_EvalCodeWithName ??:? [0x5106ED]
        #49     _PyFunction_Vectorcall ??:? [0x528D21]
U00007f48fd2a4740_python3 Mx02:/rti/jenkins/workspace/connextdds/6.1.0.0/x64Linux4gcc7.3.0/src/osapi.1.0/srcC/thread/Thread.c:3572:RTI0x2000005:Received signal SIGSEGV

Howard's picture
Offline
Last seen: 23 hours 51 min ago
Joined: 11/29/2012
Posts: 565