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 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.

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.36.tar.gz (12.5 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.36-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cantok-0.0.36.tar.gz
  • Upload date:
  • Size: 12.5 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.36.tar.gz
Algorithm Hash digest
SHA256 e1e60a7c436878b4f4b03422b7289a6c94f5bca7af76a9e5e587d9a6b4863823
MD5 d16754243821899214df8d8a652d3897
BLAKE2b-256 7b238d14eb79edc9f4a00379f1956720d84b94ada9d594ee36e06fb886d06b1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cantok-0.0.36.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.36-py3-none-any.whl.

File metadata

  • Download URL: cantok-0.0.36-py3-none-any.whl
  • Upload date:
  • Size: 15.1 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.36-py3-none-any.whl
Algorithm Hash digest
SHA256 9f3e29807547ad5b303a7d3195b9bde20cae4d027bcba0f78e84a425b0f070c7
MD5 0f7bfc62b0587f48eff63c2b749d2887
BLAKE2b-256 41f0931c0df6f7a5d5256e924c6a57ad86ebaa7500de3f8eb0d7d561401d7ef6

See more details on using hashes here.

Provenance

The following attestation bundles were made for cantok-0.0.36-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