Quick start

Consider an example:

from random import randint
from cantok import ConditionToken, CounterToken, TimeoutToken


token = ConditionToken(lambda: randint(1, 100_000) == 1984) + CounterToken(400_000, direct=False) + TimeoutToken(1)
counter = 0

while token:
  counter += 1

print(counter)

In this code, we use a token that describes several restrictions: on the number of iterations of the loop, on time, as well as on the occurrence of a random unlikely event. When any of the listed events occur, the loop stops.

In fact, the library's capabilities are much broader. Read the documentation below.