Skip to main content

Implementation of the "Cancellation Token" pattern

Project description

Downloads Downloads Coverage Status Lines of code Hits-of-Code Test-Package Python versions PyPI version Checked with mypy Ruff DeepWiki

logo

Cancellation Token is a pattern that allows us to refuse to continue 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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cantok-0.0.34.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cantok-0.0.34-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file cantok-0.0.34.tar.gz.

File metadata

  • Download URL: cantok-0.0.34.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cantok-0.0.34.tar.gz
Algorithm Hash digest
SHA256 f4b7f171d11805eebade2d88884b6c13a5628267252d99b765f7d0da3fc0a692
MD5 28fc325cec79d89edd1720e818795976
BLAKE2b-256 953fa46f05491d300c6c532ad3ae13cec8448ef86c98c12786b515390b25b5f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cantok-0.0.34.tar.gz:

Publisher: release.yml on pomponchik/cantok

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cantok-0.0.34-py3-none-any.whl.

File metadata

  • Download URL: cantok-0.0.34-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cantok-0.0.34-py3-none-any.whl
Algorithm Hash digest
SHA256 8504e54d8562e8874126c0d7d7df42498eea0c0133fc772f402b639a04861dfb
MD5 3e9005670f12d414f9c34a670d7fcc0a
BLAKE2b-256 811bc977341e29060e7ce271014f47afd2bb5c2b0fd64947ebdc34c1f41c2950

See more details on using hashes here.

Provenance

The following attestation bundles were made for cantok-0.0.34-py3-none-any.whl:

Publisher: release.yml on pomponchik/cantok

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page