Skip to content

Commit 1bf6e06

Browse files
committed
fix: schedule unawaited coroutine in send_to_parent with ensure_future
When the child machine runs inside the parent's async event loop, send_to_parent returns an unawaited coroutine from AsyncEngine's processing_loop. Use asyncio.ensure_future to schedule it as a task on the running loop instead of dropping it.
1 parent 53b2c06 commit 1bf6e06

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

statemachine/io/scxml/invoke.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
finalize.
77
"""
88

9+
import asyncio
910
import logging
11+
from inspect import isawaitable
1012
from pathlib import Path
1113
from typing import Any
1214
from typing import Callable
@@ -222,7 +224,9 @@ def __init__(self, parent, invokeid: str):
222224

223225
def send_to_parent(self, event: str, **data):
224226
"""Send an event to the parent machine's external queue."""
225-
self.parent.send(event, _invokeid=self.invokeid, **data)
227+
result = self.parent.send(event, _invokeid=self.invokeid, **data)
228+
if isawaitable(result):
229+
asyncio.ensure_future(result)
226230

227231

228232
# Verify protocol compliance at import time

0 commit comments

Comments
 (0)