Cancellation Token is a pattern that allows us to cancel calculations that we no longer need. It is implemented out of the box in many programming languages, for example in C# and in Go. However, there was still no sane implementation in Python, until the cantok library appeared.
Quick start
Install it:
pip install cantok
And use:
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)
Read more in the documentation.
Metadata
Release files for cantok 0.0.43
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cantok-0.0.43.tar.gz | 11.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cantok-0.0.43-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.8 kB
Release files / cantok-0.0.43.tar.gz
| Download URL | cantok-0.0.43.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e40e16b4bfcbd5dcbdc036cac16ff64bb753a89b378837ec8a8b7ca90bc953d9
|
|
BLAKE2b-256 checksum How to use checksums |
ac67d7ca148e312ca5b624d3caf7185a8f7760a694e1c9597b2850f5dd635392
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 20, 2026.
Transparency logRelease files / cantok-0.0.43-py3-none-any.whl
| Download URL | cantok-0.0.43-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8f5288fce95acc1c359264fbde27146e91f08c599bf700884b7c4f35c9328c28
|
|
BLAKE2b-256 checksum How to use checksums |
57ceb7287569531994f3e1513b72c583dbd4db97bcec63c63183c8d3393049c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 20, 2026.
Transparency log