Skip to content

Commit e07c927

Browse files
committed
Fix python 2.7 compatibility
1 parent 27dd785 commit e07c927

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

src/roslibpy/actionlib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import time
3030

3131
from . import Message, Topic
32+
from .core import RosTimeoutError
3233
from .event_emitter import EventEmitterMixin
3334

3435
__all__ = ["Goal", "GoalStatus", "ActionClient", "SimpleActionServer"]
@@ -136,7 +137,7 @@ def wait(self, timeout=None):
136137
Result of the goal.
137138
"""
138139
if not self.wait_result.wait(timeout):
139-
raise TimeoutError("Goal failed to receive result")
140+
raise RosTimeoutError("Goal failed to receive result")
140141

141142
return self.result
142143

@@ -226,7 +227,7 @@ def __init__(
226227
self.wait_status = threading.Event()
227228

228229
if not self.wait_status.wait(DEFAULT_CONNECTION_TIMEOUT):
229-
raise TimeoutError("Action client failed to connect, no status received.")
230+
raise RosTimeoutError("Action client failed to connect, no status received.")
230231

231232
def _on_status_message(self, message):
232233
self.wait_status.set()

src/roslibpy/comm/comm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
class RosBridgeException(Exception):
1212
"""Exception raised on the ROS bridge communication."""
1313

14-
pass
14+
def __init__(self, message, cause=None):
15+
super(RosBridgeException, self).__init__(message, cause)
1516

1617

1718
class RosBridgeProtocol(object):

src/roslibpy/comm/comm_autobahn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from twisted.internet.protocol import ReconnectingClientFactory
1414
from twisted.python import log
1515

16+
from ..core import RosTimeoutError
1617
from ..event_emitter import EventEmitterMixin
1718
from . import RosBridgeProtocol
1819

@@ -232,7 +233,7 @@ def raise_timeout_exception(self, _result=None, _timeout=None):
232233
Raises:
233234
An exception.
234235
"""
235-
raise TimeoutError("No service response received")
236+
raise RosTimeoutError("No service response received")
236237

237238
def get_inner_callback(self, result_placeholder):
238239
"""Get the callback which, when called, provides result_placeholder with the result.

src/roslibpy/comm/comm_cli.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525
from System.Threading.Tasks import Task
2626

27+
from ..core import RosTimeoutError
2728
from ..event_emitter import EventEmitterMixin
2829
from . import RosBridgeException, RosBridgeProtocol
2930

@@ -131,7 +132,7 @@ def receive_chunk_async(self, task, context):
131132
if task:
132133
error_message += '; Task status: {}, Inner exception: {}'.format(task.Status, task.Exception)
133134
LOGGER.exception(error_message)
134-
raise RosBridgeException(error_message) from exception
135+
raise RosBridgeException(error_message, exception)
135136

136137
def start_listening(self):
137138
"""Starts listening asynchronously while the socket is open.
@@ -167,7 +168,7 @@ def start_listening(self):
167168
except Exception as exception:
168169
error_message = 'Exception on start_listening, processing will be aborted'
169170
LOGGER.exception(error_message)
170-
raise RosBridgeException(error_message) from exception
171+
raise RosBridgeException(error_message, exception)
171172
finally:
172173
LOGGER.debug('Leaving the listening thread')
173174

@@ -223,7 +224,7 @@ def send_chunk_async(self, task, message_data):
223224
except Exception as exception:
224225
error_message = 'Exception while on send_chunk_async'
225226
LOGGER.exception(error_message)
226-
raise RosBridgeException(error_message) from exception
227+
raise RosBridgeException(error_message, exception)
227228

228229
def send_message(self, payload):
229230
"""Start sending a message over the websocket asynchronously."""
@@ -244,7 +245,7 @@ def send_message(self, payload):
244245
except Exception as exception:
245246
error_message = 'Exception while sending message'
246247
LOGGER.exception(error_message)
247-
raise RosBridgeException(error_message) from exception
248+
raise RosBridgeException(error_message, exception)
248249

249250
def dispose(self, *args):
250251
"""Dispose the resources held by this protocol instance, i.e. socket."""
@@ -486,7 +487,7 @@ def raise_timeout_exception(self, _result=None, _timeout=None):
486487
Raises:
487488
An exception.
488489
"""
489-
raise TimeoutError('No service response received')
490+
raise RosTimeoutError('No service response received')
490491

491492
def get_inner_callback(self, result_placeholder):
492493
"""Get the callback which, when called, provides result_placeholder with the result.

src/roslibpy/core.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212

1313
LOGGER = logging.getLogger("roslibpy")
1414

15-
__all__ = ["Header", "Message", "Param", "Service", "ServiceRequest", "ServiceResponse", "Time", "Topic"]
15+
__all__ = ["Header", "Message", "Param", "RosTimeoutError", "Service", "ServiceRequest", "ServiceResponse", "Time", "Topic"]
16+
17+
18+
try:
19+
class RosTimeoutError(TimeoutError):
20+
pass
21+
except NameError:
22+
class RosTimeoutError(Exception):
23+
pass
1624

1725

1826
class Message(UserDict):

src/roslibpy/ros.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from . import Message, Param, Service, ServiceRequest, Time
77
from .comm import RosBridgeClientFactory
8+
from .core import RosTimeoutError
89

910
__all__ = ["Ros", "set_rosapi_timeout"]
1011

@@ -96,7 +97,7 @@ def run(self, timeout=CONNECTION_TIMEOUT):
9697
self.factory.on_ready(lambda _: wait_connect.set())
9798

9899
if not wait_connect.wait(timeout):
99-
raise TimeoutError("Failed to connect to ROS")
100+
raise RosTimeoutError("Failed to connect to ROS")
100101

101102
def run_forever(self):
102103
"""Kick-starts a blocking loop to wait for events.

0 commit comments

Comments
 (0)