Skip to content

Commit 068ef6d

Browse files
committed
Check that event loop is running before trying to set future result
1 parent e08690b commit 068ef6d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/aalink.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ struct Scheduler {
8888
if (link_beat > it->link_beat) {
8989
nb::gil_scoped_acquire acquire;
9090

91-
auto loop_call_soon_threadsafe = m_loop.attr("call_soon_threadsafe");
92-
loop_call_soon_threadsafe(nb::cpp_function(&set_future_result), it->future, it->link_beat);
91+
bool loop_is_running = nb::cast<bool>(m_loop.attr("is_running")());
92+
93+
if (loop_is_running) {
94+
auto loop_call_soon_threadsafe = m_loop.attr("call_soon_threadsafe");
95+
loop_call_soon_threadsafe(nb::cpp_function(&set_future_result), it->future, it->link_beat);
96+
}
9397

9498
it = m_events.erase(it);
9599
} else {

0 commit comments

Comments
 (0)