Skip to content

Commit 6c730d2

Browse files
sloretzivanpauno
authored andcommitted
Release loop lock before waiting for it to do work (#369)
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]>
1 parent a7f53f8 commit 6c730d2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

launch/launch/launch_service.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,22 @@ def emit_event(self, event: Event) -> None:
127127
128128
If the LaunchService is not running, the event is queued until it is.
129129
"""
130+
future = None
130131
with self.__loop_from_run_thread_lock:
131132
if self.__loop_from_run_thread is not None:
132133
# loop is in use, asynchronously emit the event
133134
future = asyncio.run_coroutine_threadsafe(
134135
self.__context.emit_event(event),
135136
self.__loop_from_run_thread
136137
)
137-
future.result()
138138
else:
139139
# loop is not in use, synchronously emit the event, and it will be processed later
140140
self.__context.emit_event_sync(event)
141141

142+
if future is not None:
143+
# Block until asynchronously emitted event is emitted by loop
144+
future.result()
145+
142146
def include_launch_description(self, launch_description: LaunchDescription) -> None:
143147
"""
144148
Evaluate a given LaunchDescription and visits all of its entities.

0 commit comments

Comments
 (0)