Skip to content

Commit

Permalink
removed deprecated loop parameter call (#387) (#410)
Browse files Browse the repository at this point in the history
Signed-off-by: zmk5 <zkakish@gmail.com>
  • Loading branch information
zmk5 authored Apr 30, 2020
1 parent d2821d3 commit cac43b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 0 additions & 1 deletion launch/launch/actions/timer_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def __init__(
async def __wait_to_fire_event(self, context):
done, pending = await asyncio.wait(
[self.__canceled_future],
loop=context.asyncio_loop,
timeout=float(perform_substitutions(context, self.__period)),
)
if not self.__canceled_future.done():
Expand Down
13 changes: 6 additions & 7 deletions launch/launch/launch_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,23 @@ def _is_idle(self):
return number_of_entity_future_pairs == 0 and self.__context._event_queue.empty()

@contextlib.contextmanager
def _prepare_run_loop(self, loop):
def _prepare_run_loop(self):
try:
# Acquire the lock and initialize the loop.
with self.__loop_from_run_thread_lock:
if self.__loop_from_run_thread is not None:
raise RuntimeError(
'LaunchService cannot be run multiple times concurrently.'
)
this_loop = asyncio.get_event_loop() if loop is None else loop
this_loop = asyncio.get_event_loop()

if self.__debug:
this_loop.set_debug(True)

# Set the asyncio loop for the context.
self.__context._set_asyncio_loop(this_loop)
# Recreate the event queue to ensure the same event loop is being used.
new_queue = asyncio.Queue(loop=this_loop)
new_queue = asyncio.Queue()
while True:
try:
new_queue.put_nowait(self.__context._event_queue.get_nowait())
Expand Down Expand Up @@ -299,7 +299,7 @@ async def __process_event(self, event: Event) -> None:
# 'launch.LaunchService',
# "processing event: '{}' x '{}'".format(event, event_handler))

async def run_async(self, *, shutdown_when_idle=True, loop=None) -> int:
async def run_async(self, *, shutdown_when_idle=True) -> int:
"""
Visit all entities of all included LaunchDescription instances asynchronously.
Expand All @@ -318,7 +318,7 @@ async def run_async(self, *, shutdown_when_idle=True, loop=None) -> int:
)

return_code = 0
with self._prepare_run_loop(loop) as (this_loop, this_task):
with self._prepare_run_loop() as (this_loop, this_task):
# Log logging configuration details.
launch.logging.log_launch_config(logger=self.__logger)

Expand Down Expand Up @@ -351,7 +351,6 @@ def _on_exception(loop, context):
while not done:
done, pending = await asyncio.wait(
entity_futures,
loop=this_loop,
timeout=1.0,
return_when=asyncio.FIRST_COMPLETED
)
Expand Down Expand Up @@ -389,7 +388,7 @@ def run(self, *, shutdown_when_idle=True) -> int:
"""
loop = osrf_pycommon.process_utils.get_loop()
run_async_task = loop.create_task(self.run_async(
shutdown_when_idle=shutdown_when_idle, loop=loop
shutdown_when_idle=shutdown_when_idle
))
loop.run_until_complete(run_async_task)
return run_async_task.result()
Expand Down

0 comments on commit cac43b1

Please sign in to comment.