Python timeout not detected
Thanks a lot for durable rules. This is a well written and powerful reasoning tool.
My issue relates to the timer examples in Python.
My environment: Python 3.6.9 on Mac
What did I run:
from durable.lang import *
with ruleset('timer'):
@when_all(m.subject == 'start')
def start(c):
c.start_timer('MyTimer', 5)
print("timer started")
@when_all(timeout('MyTimer'))
def timer(c):
print('timer timeout')
post('timer', { 'subject': 'start' })
This is one of the timer examples from the readme with an added print statement.
What did I see: The output I see when I run this is:
> python timer1.py
timer started
>
The program seems to exit immediately after starting the timer. I do not see the print statement corresponding to the timeout at all. Shouldn't the program wait (without exiting) for the timeout to occur and then exit after executing the timeout rule?
The timer creation does work... however, the program seems to be exiting even though a timer was created -- which I am not sure is the desired behavior. Anyway, the following code does behave as expected.
from durable.lang import *
import threading
def hello():
print("Hello World")
with ruleset('timer'):
@when_all(m.subject == 'start')
def start(c):
c.start_timer('MyTimer', 5)
print("timer started")
@when_all(timeout('MyTimer'))
def timer(c):
print('timer timeout')
post('timer', { 'subject': 'start' })
timer = threading.Timer(10.0, hello)
timer.start()
print("exit")
When I run the above, I get:
> python timer1.py
timer started
exit
timer timeout
Hello World
Hi, thanks for asking the question. The behavior is expected, as the rules engine doesn't block the main thread (this way you can use it with other frameworks such as flask). I will modify the examples to reflect the behavior.