Skip to content

Commit

Permalink
Initialize ROS service servers only after all state they depend on ha…
Browse files Browse the repository at this point in the history
…s be initialized
  • Loading branch information
phantamanta44 committed Jun 2, 2021
1 parent 3d96b79 commit 50feb7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/wready/wready_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def __init__(self, server_ns: str, notify_service: Optional[str] = None):
req_srv_name = f'{server_ns}/request'
rospy.wait_for_service(req_srv_name)
self._cli_req = rospy.ServiceProxy(req_srv_name, InitRequest)
self._srv_notify = rospy.Service(notify_service or '~wready_notify', InitNotify, self._on_notify_req)
self._cli_progress = rospy.ServiceProxy(f'{server_ns}/progress', InitProgress, persistent=True)
self._cli_done = rospy.ServiceProxy(f'{server_ns}/done', Empty)

Expand All @@ -102,6 +101,8 @@ def __init__(self, server_ns: str, notify_service: Optional[str] = None):
self._task_callback_cond = Condition(self._task_callback_lock)

self._sig_int_handler = SignalInterruptHandler(self.kill)

self._srv_notify = rospy.Service(notify_service or '~wready_notify', InitNotify, self._on_notify_req)

def request_sync(self, task_name: str) -> ContextManager[TaskContext]:
"""Requests a task that is completed immediately on the current thread.
Expand Down
7 changes: 4 additions & 3 deletions src/wready/wready_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ def __init__(self, server_ns: Optional[str] = None, observer: Optional[WReadySer
An observer for this WReady server, if any.
"""
namespace = '~' if server_ns is None else f'{server_ns}/'
self._srv_req = rospy.Service(f'{namespace}request', InitRequest, self._on_request_req)
self._srv_progress = rospy.Service(f'{namespace}progress', InitProgress, self._on_progress_req)
self._srv_done = rospy.Service(f'{namespace}done', Empty, self._on_done_req)

self._last_task_id = -1
self._req_queue: Deque[InitTask] = deque()
Expand All @@ -112,6 +109,10 @@ def __init__(self, server_ns: Optional[str] = None, observer: Optional[WReadySer

self.observer = observer
self._sig_int_handler = SignalInterruptHandler(self.kill)

self._srv_req = rospy.Service(f'{namespace}request', InitRequest, self._on_request_req)
self._srv_progress = rospy.Service(f'{namespace}progress', InitProgress, self._on_progress_req)
self._srv_done = rospy.Service(f'{namespace}done', Empty, self._on_done_req)

def _next_task_id(self) -> int:
"""Produces an unused task slot ID.
Expand Down

0 comments on commit 50feb7d

Please sign in to comment.