transitions
transitions copied to clipboard
Async TimeoutError gets caught inappropriately
When using the AsyncMachine, any asyncio.TimeoutError that gets raised during a manipulation of the state machine gets eaten by it and process outside of state machine keep going as if nothing happened.
import asyncio
from transitions.extensions.asyncio import AsyncMachine
class Model:
async def on_enter_on(self):
await asyncio.sleep(1)
assert False, "Shouldn't be reachable due to timeout"
machine = AsyncMachine(
Model(),
states=["off", "on"],
transitions=[{"trigger": "start", "source": "off", "dest": "on"}],
initial="off"
)
async def foo():
await machine.model.start()
assert False, "Shouldn't be reachable due to timeout" # <-- This assert trigger
async def main():
try:
await asyncio.wait_for(foo(), timeout=0.5)
except asyncio.TimeoutError:
return # expected case
assert False, "Expected a TimeoutError"
asyncio.run(main())
I expect the Timeout exception to be raised if no particular comportment for exceptions is indicated. Particularly in the case where the timeout extension is not used or is not specified for the current transition.
I did not test this with https://github.com/pytransitions/transitions/pull/686 so unsure if it is fixed with that timeout rework. But if it is could a release be planned soon?