Skip to content

Commit

Permalink
Release loop lock before waiting for it to do work (#369)
Browse files Browse the repository at this point in the history
Main thread can be blocked trying to acquire
__loop_from_run_thread_lock while emit_event() in another thread is
holding that lock and waiting for the main thread to emit the event.
This change releases the lock before blocking.

Signed-off-by: Shane Loretz <[email protected]>
  • Loading branch information
sloretz authored and ivanpauno committed Jan 17, 2020
1 parent a7f53f8 commit 6c730d2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion launch/launch/launch_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,22 @@ def emit_event(self, event: Event) -> None:
If the LaunchService is not running, the event is queued until it is.
"""
future = None
with self.__loop_from_run_thread_lock:
if self.__loop_from_run_thread is not None:
# loop is in use, asynchronously emit the event
future = asyncio.run_coroutine_threadsafe(
self.__context.emit_event(event),
self.__loop_from_run_thread
)
future.result()
else:
# loop is not in use, synchronously emit the event, and it will be processed later
self.__context.emit_event_sync(event)

if future is not None:
# Block until asynchronously emitted event is emitted by loop
future.result()

def include_launch_description(self, launch_description: LaunchDescription) -> None:
"""
Evaluate a given LaunchDescription and visits all of its entities.
Expand Down

0 comments on commit 6c730d2

Please sign in to comment.