Skip to main content

Implementation of the "Cancellation Token" pattern

Project description

logo

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

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 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.32.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

cantok-0.0.32-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cantok-0.0.32.tar.gz
Algorithm Hash digest
SHA256 2b39be7244b2310d9811942ccb4824a27f96e038f71fde1c3f94c9283f21e54d
MD5 3599e2318479e89abdf6aac0043171e2
BLAKE2b-256 f2518f650102f8d89aa44f1196f6d0a8055ee9da2ee4e61560d5e773fa8c3b50

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for cantok-0.0.32-py3-none-any.whl
Algorithm Hash digest
SHA256 dfca642eae45887d24b3ec170cd7432831895bf2338e454e8bcdaf45aa9829b6
MD5 9b627c2d7dc058d105546ba7d1e62a8d
BLAKE2b-256 5488845a66c175de4b6039f64cc97483c956e3da66f7734820e766be020d101a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cantok-0.0.32-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 Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page