From 612006156839402471e22e2af4f291db4346bb69 Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Fri, 11 Mar 2022 09:45:00 +0900 Subject: [PATCH] [compat] Fixed to catch CORBA_RTCUtil exception. --- OpenRTM_aist/InPortBase.py | 12 ++++- OpenRTM_aist/InPortPullConnector.py | 5 +- OpenRTM_aist/InPortPushConnector.py | 2 +- OpenRTM_aist/Manager.py | 70 +++++++++++++++++++++------- OpenRTM_aist/OutPortBase.py | 12 ++++- OpenRTM_aist/OutPortPullConnector.py | 5 +- OpenRTM_aist/OutPortPushConnector.py | 9 ++-- 7 files changed, 84 insertions(+), 31 deletions(-) diff --git a/OpenRTM_aist/InPortBase.py b/OpenRTM_aist/InPortBase.py index c02534ac..8af374eb 100644 --- a/OpenRTM_aist/InPortBase.py +++ b/OpenRTM_aist/InPortBase.py @@ -1260,7 +1260,11 @@ def createProvider(self, cprof, prop): if provider is not None: self._rtcout.RTC_DEBUG("provider created") - provider.init(prop.getNode("provider")) + try: + provider.init(prop.getNode("provider")) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + return None if not provider.publishInterface(cprof.properties): self._rtcout.RTC_ERROR( @@ -1304,7 +1308,11 @@ def createConsumer(self, cprof, prop): if consumer is not None: self._rtcout.RTC_DEBUG("consumer created") - consumer.init(prop.getNode("consumer")) + try: + consumer.init(prop.getNode("consumer")) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + return None if not consumer.subscribeInterface(cprof.properties): self._rtcout.RTC_ERROR("interface subscription failed.") diff --git a/OpenRTM_aist/InPortPullConnector.py b/OpenRTM_aist/InPortPullConnector.py index d340ae26..0cb61b7b 100644 --- a/OpenRTM_aist/InPortPullConnector.py +++ b/OpenRTM_aist/InPortPullConnector.py @@ -133,7 +133,7 @@ def __init__(self, info, consumer, listeners, buffer=None): self._buffer = self.createBuffer(self._profile) if not self._buffer or not self._consumer: - raise + raise MemoryError("InPortPullConnector creation failed") self._buffer.init(info.properties.getNode("buffer")) self._consumer.init(info.properties) @@ -414,4 +414,5 @@ def unsubscribeInterface(self, prop): def setDataType(self, data): OpenRTM_aist.InPortConnector.setDataType(self, data) - self._serializer = OpenRTM_aist.SerializerFactories.instance().createSerializer(self._marshaling_type, data) \ No newline at end of file + self._serializer = OpenRTM_aist.SerializerFactories.instance( + ).createSerializer(self._marshaling_type, data) diff --git a/OpenRTM_aist/InPortPushConnector.py b/OpenRTM_aist/InPortPushConnector.py index 07088d48..31f81bea 100644 --- a/OpenRTM_aist/InPortPushConnector.py +++ b/OpenRTM_aist/InPortPushConnector.py @@ -131,7 +131,7 @@ def __init__(self, info, provider, listeners, buffer=None): self._buffer = self.createBuffer(info) if self._buffer is None or not self._provider: - raise + raise MemoryError("InPortPushConnector creation failed") self._buffer.init(info.properties.getNode("buffer")) self._provider.init(info.properties) diff --git a/OpenRTM_aist/Manager.py b/OpenRTM_aist/Manager.py index fda03af6..bd40e058 100644 --- a/OpenRTM_aist/Manager.py +++ b/OpenRTM_aist/Manager.py @@ -3122,9 +3122,13 @@ def connectDataPorts(self, port, target_ports): con_name += ":" con_name += p1.name prop = OpenRTM_aist.Properties() - if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( - con_name, prop, port, p): - self._rtcout.RTC_ERROR("Connection error in topic connection.") + try: + if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( + con_name, prop, port, p): + self._rtcout.RTC_ERROR( + "Connection error in topic connection.") + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) ## # @if jp @@ -3153,9 +3157,13 @@ def connectServicePorts(self, port, target_ports): con_name += ":" con_name += p1.name prop = OpenRTM_aist.Properties() - if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( - con_name, prop, port, p): - self._rtcout.RTC_ERROR("Connection error in topic connection.") + try: + if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( + con_name, prop, port, p): + self._rtcout.RTC_ERROR( + "Connection error in topic connection.") + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) ## # @if jp @@ -3233,8 +3241,13 @@ def initPreConnection(self): comp0_ref = rtcs[0] port0_name = port0_str.split("/")[-1] - port0_var = OpenRTM_aist.CORBA_RTCUtil.get_port_by_name( - comp0_ref, port0_name) + port0_var = None + try: + port0_var = OpenRTM_aist.CORBA_RTCUtil.get_port_by_name( + comp0_ref, port0_name) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + continue if CORBA.is_nil(port0_var): self._rtcout.RTC_DEBUG("port %s not found: " % port0_str) @@ -3248,9 +3261,14 @@ def initPreConnection(self): v = v.strip() prop.setProperty("dataport." + k, v) - if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( - c, prop, port0_var, RTC.PortService._nil): - self._rtcout.RTC_ERROR("Connection error: %s" % c) + try: + if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( + c, prop, port0_var, RTC.PortService._nil): + self._rtcout.RTC_ERROR("Connection error: %s" % c) + except BaseException: + self._rtcout.RTC_ERROR( + OpenRTM_aist.Logger.print_exception()) + continue for port_str in ports: @@ -3278,8 +3296,14 @@ def initPreConnection(self): comp_ref = rtcs[0] port_name = port_str.split("/")[-1] - port_var = OpenRTM_aist.CORBA_RTCUtil.get_port_by_name( - comp_ref, port_name) + port_var = None + try: + port_var = OpenRTM_aist.CORBA_RTCUtil.get_port_by_name( + comp_ref, port_name) + except BaseException: + self._rtcout.RTC_ERROR( + OpenRTM_aist.Logger.print_exception()) + continue if CORBA.is_nil(port_var): self._rtcout.RTC_DEBUG("port %s not found: " % port_str) @@ -3291,10 +3315,13 @@ def initPreConnection(self): k = k.strip() v = v.strip() prop.setProperty("dataport." + k, v) - - if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( - c, prop, port0_var, port_var): - self._rtcout.RTC_ERROR("Connection error: %s" % c) + try: + if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( + c, prop, port0_var, port_var): + self._rtcout.RTC_ERROR("Connection error: %s" % c) + except BaseException: + self._rtcout.RTC_ERROR( + OpenRTM_aist.Logger.print_exception()) ## # @if jp @@ -3330,7 +3357,14 @@ def initPreActivation(self): self._rtcout.RTC_ERROR("%s not found." % c) continue comp_ref = rtcs[0] - ret = OpenRTM_aist.CORBA_RTCUtil.activate(comp_ref) + ret = RTC.RTC_OK + try: + ret = OpenRTM_aist.CORBA_RTCUtil.activate(comp_ref) + except BaseException: + self._rtcout.RTC_ERROR( + OpenRTM_aist.Logger.print_exception()) + continue + if ret != RTC.RTC_OK: self._rtcout.RTC_ERROR("%s activation failed." % c) else: diff --git a/OpenRTM_aist/OutPortBase.py b/OpenRTM_aist/OutPortBase.py index c6ab706e..43504cd5 100644 --- a/OpenRTM_aist/OutPortBase.py +++ b/OpenRTM_aist/OutPortBase.py @@ -1269,7 +1269,11 @@ def createProvider(self, cprof, prop): if provider is not None: self._rtcout.RTC_DEBUG("provider created") - provider.init(prop.getNode("provider")) + try: + provider.init(prop.getNode("provider")) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + return None if not provider.publishInterface(cprof.properties): self._rtcout.RTC_ERROR( @@ -1311,7 +1315,11 @@ def createConsumer(self, cprof, prop): if consumer is not None: self._rtcout.RTC_DEBUG("consumer created") - consumer.init(prop.getNode("consumer")) + try: + consumer.init(prop.getNode("consumer")) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + return None if not consumer.subscribeInterface(cprof.properties): self._rtcout.RTC_ERROR("interface subscription failed.") diff --git a/OpenRTM_aist/OutPortPullConnector.py b/OpenRTM_aist/OutPortPullConnector.py index ce22588d..83b826a1 100644 --- a/OpenRTM_aist/OutPortPullConnector.py +++ b/OpenRTM_aist/OutPortPullConnector.py @@ -134,7 +134,7 @@ def __init__(self, info, provider, listeners, buffer=None): if not self._provider or not self._buffer: self._rtcout.RTC_ERROR( "Exeption: in OutPortPullConnector.__init__().") - raise + raise MemoryError("OutPortPullConnector creation failed") self._buffer.init(info.properties.getNode("buffer")) self._provider.init(info.properties) @@ -417,7 +417,8 @@ def setDirectMode(self): def setDataType(self, data): OpenRTM_aist.OutPortConnector.setDataType(self, data) - self._serializer = OpenRTM_aist.SerializerFactories.instance().createSerializer(self._marshaling_type, data) + self._serializer = OpenRTM_aist.SerializerFactories.instance( + ).createSerializer(self._marshaling_type, data) class WorkerThreadCtrl: def __init__(self): diff --git a/OpenRTM_aist/OutPortPushConnector.py b/OpenRTM_aist/OutPortPushConnector.py index 03666796..3b906a71 100644 --- a/OpenRTM_aist/OutPortPushConnector.py +++ b/OpenRTM_aist/OutPortPushConnector.py @@ -139,17 +139,17 @@ def __init__(self, info, consumer, listeners, buffer=None): self._buffer = self.createBuffer(info) if not self._publisher or not self._buffer or not self._consumer: - raise + raise MemoryError("OutPortPushConnector creation failed") if self._publisher.init(info.properties) != self.PORT_OK: - raise + raise MemoryError("OutPortPushConnector creation failed") if self._profile.properties.hasKey("serializer"): endian = self._profile.properties.getProperty( "serializer.cdr.endian") if not endian: self._rtcout.RTC_ERROR("write(): endian is not set.") - raise + raise MemoryError("OutPortPushConnector creation failed") # Maybe endian is ["little","big"] endian = OpenRTM_aist.split(endian, ",") @@ -517,4 +517,5 @@ def unsubscribeInterface(self, prop): def setDataType(self, data): OpenRTM_aist.OutPortConnector.setDataType(self, data) - self._serializer = OpenRTM_aist.SerializerFactories.instance().createSerializer(self._marshaling_type, data) + self._serializer = OpenRTM_aist.SerializerFactories.instance( + ).createSerializer(self._marshaling_type, data)