Skip to content

Commit 7f0595f

Browse files
committed
docs(invoke): explain why error.execution uses the external queue
Invoke handlers run in background threads, outside the processing loop. Using the internal queue would either contaminate an unrelated macrostep or stall indefinitely. This matches done.invoke, which also uses the external queue for the same reason.
1 parent 3cab153 commit 7f0595f

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

statemachine/invoke.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@ def _run_sync_handler(
391391
)
392392
except Exception as e:
393393
if not ctx.cancelled.is_set():
394+
# Intentionally using the external queue (no internal=True):
395+
# This handler runs in a background thread, outside the processing
396+
# loop. Using the internal queue would either contaminate an
397+
# unrelated macrostep in progress, or stall if no macrostep is
398+
# active (the internal queue is only drained within a macrostep).
399+
# This matches done.invoke, which also uses the external queue.
394400
self.sm.send("error.execution", error=e)
395401
finally:
396402
invocation.terminated = True
@@ -459,6 +465,7 @@ async def _run_async_handler(
459465
return
460466
except Exception as e:
461467
if not ctx.cancelled.is_set():
468+
# External queue — see comment in _run_sync_handler.
462469
self.sm.send("error.execution", error=e)
463470
finally:
464471
invocation.terminated = True

0 commit comments

Comments
 (0)