apollo icon indicating copy to clipboard operation
apollo copied to clipboard

help: how to control reader working period subscribing same channel

Open SdKay opened this issue 1 year ago • 1 comments

Describe the bug I use Apollo 7 with python I want to create reader sub same channel in different period and with different callback(in different module, and earlier callback is not supposed to be called), so I try with code below:

def callback1(data):
    print("callback1")

def callback2(data):
    print("callback2")

cyber.init()
node = cyber.Node("a")
node.create_reader('/apollo/planning', ADCTrajectory, callback1)
time.sleep(3)

node.create_reader('/apollo/planning', ADCTrajectory, callback2)
time.sleep(3)

if cyber.ok(): cyber.shutdown()
cyber.waitforshutdown()

but thecallback1 is still called rather than callback2. Then I try create two node, the code below:

def callback1(data):
    print("callback1")

def callback2(data):
    print("callback2")

cyber.init()
node1 = cyber.Node("a")
node1.create_reader('/apollo/planning', ADCTrajectory, callback1)
time.sleep(3)

node2 = cyber.Node("b")
node2.create_reader('/apollo/planning', ADCTrajectory, callback2)
time.sleep(3)

if cyber.ok(): cyber.shutdown()
cyber.waitforshutdown()

Then callback1 and callback2 both are called, but I want Only callback2 called, find no way to shutdown node1 I also try with code below, but still not working

def callback1(data):
    print("callback1")

def callback2(data):
    print("callback2")

cyber.init()
node1 = cyber.Node("a")
node1.create_reader('/apollo/planning', ADCTrajectory, callback1)
time.sleep(3)
if cyber.ok(): cyber.shutdown()
cyber.waitforshutdown()

cyber.init()
node2 = cyber.Node("b")
node2.create_reader('/apollo/planning', ADCTrajectory, callback2)
time.sleep(3)

if cyber.ok(): cyber.shutdown()
cyber.waitforshutdown()

signal SIGSEGV trigged on second cyber.init, backtrace is below:

Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
0x0000555555e4c4a0 in ?? ()
(gdb) bt
#0  0x0000555555e4c4a0 in ?? ()
#1  0x00007ffff55c4558 in google::LogDestination::MaybeLogToLogfile(int, long, char const*, unsigned long) () from /apollo/bazel-bin/cyber/python/internal/_cyber_wrapper.so
#2  0x00007ffff55c45ba in google::LogDestination::LogToAllLogfiles(int, long, char const*, unsigned long) () from /apollo/bazel-bin/cyber/python/internal/_cyber_wrapper.so
#3  0x00007ffff55bfeee in google::LogMessage::SendToLog() () from /apollo/bazel-bin/cyber/python/internal/_cyber_wrapper.so
#4  0x00007ffff55bfb04 in google::LogMessage::Flush() () from /apollo/bazel-bin/cyber/python/internal/_cyber_wrapper.so
#5  0x00007ffff55bf909 in google::LogMessage::~LogMessage() () from /apollo/bazel-bin/cyber/python/internal/_cyber_wrapper.so
#6  0x00007ffff53d64cc in apollo::cyber::py_init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
   from /apollo/bazel-bin/cyber/python/internal/_cyber_wrapper.so
#7  0x00007ffff53c76b3 in cyber_py_init(_object*, _object*) () from /apollo/bazel-bin/cyber/python/internal/_cyber_wrapper.so

Any idea how to solve this? thanks much

SdKay avatar Sep 07 '23 03:09 SdKay

For the first code block, you need to know that each node has unique channels and cannot create two identical channels on the same node. For the question you raised, if you observe the creation method of the node, you will find that the node is a unique_ PTR, you can use unique_ The method of releasing resources in PTR is to release the resources of nodes, instead of using cell. waitforshutdown(). This command seems to release all resources.

WTSRUVF avatar Sep 08 '23 02:09 WTSRUVF