Skip to content

Commit 425df97

Browse files
committed
wraps all reactor methods in callFromThread
1 parent 5c6e481 commit 425df97

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/roslibpy/comm/comm_autobahn.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ def onClose(self, wasClean, code, reason):
4545
LOGGER.info('WebSocket connection closed: Code=%s, Reason=%s', str(code), reason)
4646

4747
def send_message(self, payload):
48-
return self.sendMessage(payload, isBinary=False, fragmentSize=None, sync=False, doNotCompress=False)
48+
return reactor.callFromThread(self.sendMessage, payload, isBinary=False, fragmentSize=None, sync=False, doNotCompress=False)
4949

5050
def send_close(self):
5151
self._manual_disconnect = True
52-
self.sendClose()
52+
reactor.callFromThread(self.sendClose)
5353

5454

5555
class AutobahnRosBridgeClientFactory(EventEmitterMixin, ReconnectingClientFactory, WebSocketClientFactory):
@@ -190,15 +190,15 @@ def call_later(self, delay, callback):
190190
delay (:obj:`int`): Number of seconds to wait before invoking the callback.
191191
callback (:obj:`callable`): Callable function to be invoked when the delay has elapsed.
192192
"""
193-
reactor.callLater(delay, callback)
193+
reactor.callFromThread(reactor.callLater, delay, callback)
194194

195195
def call_in_thread(self, callback):
196196
"""Call the given function on a thread.
197197
198198
Args:
199199
callback (:obj:`callable`): Callable function to be invoked in a thread.
200200
"""
201-
reactor.callInThread(callback)
201+
reactor.callFromThread(reactor.callInThread, callback)
202202

203203
def blocking_call_from_thread(self, callback, timeout):
204204
"""Call the given function from a thread, and wait for the result synchronously
@@ -258,6 +258,9 @@ def inner_errback(error):
258258
def terminate(self):
259259
"""Signals the termination of the main event loop."""
260260
if reactor.running:
261-
reactor.stop()
261+
reactor.callFromThread(reactor.stop)
262+
263+
if self._thread:
264+
self._thread.join()
262265

263266
self._log_observer.stop()

0 commit comments

Comments
 (0)