TimeoutToken

TimeoutToken is automatically cancelled after the time specified in seconds in the class constructor:

from time import sleep
from cantok import TimeoutToken

token = TimeoutToken(5)
print(token.cancelled)  #> False
sleep(10)
print(token.cancelled)  #> True

Just like ConditionToken, TimeoutToken can embed other tokens:

token = TimeoutToken(45, SimpleToken(), TimeoutToken(5), CounterToken(20))  # Includes all additional restrictions of the passed tokens.

By default, time is measured using perf_counter as the most accurate option. In extremely rare cases, you may need to use monotonic time; for this, use the appropriate initialization argument:

token = TimeoutToken(33, monotonic=True)