State feature: Timeout
See original GitHub issueAdds the ability to timeout an entered state. See: states.py
Keywords
timeout
(int, optional) – if passed, an entered state will timeout aftertimeout
secondson_timeout
(string/callable, optional) – will be called when timeout time has been reached
Exceptions:
- will raise an
AttributeError
whentimeout
is set buton_timeout
is not
Example Usage
from transitions import Machine
from transitions.extensions.states import add_state_features, Timeout
import time
@add_state_features(Timeout)
class CustomMachine(Machine):
pass
class Model(object):
def timeout(self):
print("Timeout!")
self.to_A()
model = Model()
states = ['A',
{'name': 'B', 'timeout': 0.3, 'on_timeout': 'timeout'},
{'name': 'C', 'timeout': 0.9, 'on_timeout': model.timeout}]
m = CustomMachine(model, states=states, initial='A')
model.to_B()
time.sleep(1) # >>> "Timeout!"
print model.state # >>> 'A'
Remark
This implementation is not thread-safe! The user may either lock the model or use LockedMachine
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Use timeouts to avoid stuck executions - AWS Step Functions
You can set a timeout for your state machine using the TimeoutSeconds field in your Amazon States Language definition. For more information, see...
Read more >Does AWS Step Functions have a timeout feature?
I want a timeout feature for the entire state machine/ emr cluster as a whole, not for each individual task like in your...
Read more >HttpSessionState.Timeout Property (System.Web.SessionState)
Gets or sets the amount of time, in minutes, allowed between requests before the session-state provider terminates the session.
Read more >Step Function State Machine has timed out - Dashbird
One of your state machines timed out because one of its tasks ran longer than the TimeoutSeconds value or failed to send a...
Read more >Using setTimeout in React components (including hooks)
The setTimeout function accepts two arguments: the first is the callback function that we want to execute, and the second specifies the timeout...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, great to see this coming. Just two small things: could you put a comment to #198: I was following #198 and overlooked this thread until yesterday. I would also check the presence of
on_timeout
with EAFPThis way, you avoid the
if
in the normal case.has been implemented and tested. Hope this enables your workflow.