From 30b604f43c9b3ffb6dd91c00ab7a228e9cd9b8ec Mon Sep 17 00:00:00 2001 From: Alexander Tiderko Date: Fri, 10 Nov 2023 15:40:32 +0100 Subject: [PATCH] fixed create subscriber node --- .../fkie_multimaster_pylib/crossbar/base_session.py | 12 ++++++------ .../fkie_node_manager_daemon/subscriber_node.py | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/fkie_multimaster_pylib/fkie_multimaster_pylib/crossbar/base_session.py b/fkie_multimaster_pylib/fkie_multimaster_pylib/crossbar/base_session.py index 24efb0ce..58712c1e 100644 --- a/fkie_multimaster_pylib/fkie_multimaster_pylib/crossbar/base_session.py +++ b/fkie_multimaster_pylib/fkie_multimaster_pylib/crossbar/base_session.py @@ -136,12 +136,6 @@ def shutdown(self): def onConnect(self): Log.info(f"{self.__class__.__name__}: autobahn connected") self.join(self.config.realm) - for (topic, handler) in self._crossbar_subscriptions: - asyncio.run_coroutine_threadsafe( - self.subcribe_async(topic, handler), self.crossbar_loop) - for topic, msg in self._crossbar_failed_publications.items(): - self.publish_to(topic, msg) - self._crossbar_failed_publications.clear() def onDisconnect(self): Log.info(f"{self.__class__.__name__}: autobahn disconnected") @@ -165,6 +159,12 @@ def onJoin(self, details): for _session_id, reg in self._registrations.items(): Log.info(f"{self.__class__.__name__}: {reg.procedure}") self.crossbar_registered = True + for (topic, handler) in self._crossbar_subscriptions: + asyncio.run_coroutine_threadsafe( + self.subcribe_async(topic, handler), self.crossbar_loop) + for topic, msg in self._crossbar_failed_publications.items(): + self.publish_to(topic, msg) + self._crossbar_failed_publications.clear() async def crossbar_connect_async(self): self.crossbar_connected = False diff --git a/fkie_node_manager_daemon/fkie_node_manager_daemon/subscriber_node.py b/fkie_node_manager_daemon/fkie_node_manager_daemon/subscriber_node.py index e2e4af14..16a2033b 100644 --- a/fkie_node_manager_daemon/fkie_node_manager_daemon/subscriber_node.py +++ b/fkie_node_manager_daemon/fkie_node_manager_daemon/subscriber_node.py @@ -27,6 +27,7 @@ import threading import time import traceback +from importlib import import_module from types import SimpleNamespace from typing import Any from typing import Callable @@ -152,9 +153,9 @@ def __init__(self, test_env=False): Log.set_ros2_logging_node(self.rosnode) Log.info(f"start subscriber for {self._topic}[{self._message_type}]") - splitted_type = self._message_type.replace('/', '.').split('.') + splitted_type = self._message_type.replace('/', '.').rsplit('.', 1) splitted_type.reverse() - module = __import__(splitted_type.pop()) + module = import_module(splitted_type.pop()) sub_class = getattr(module, splitted_type.pop()) while splitted_type: sub_class = getattr(sub_class, splitted_type.pop()) @@ -199,7 +200,7 @@ def spin(self): self.sub.destroy() print('shutdown rclpy') self.executor.shutdown() - rclpy.shutdown() + # rclpy.shutdown() print('bye!') def _init_arg_parser(self) -> argparse.ArgumentParser: