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

Uploaded Source

Built Distribution

cantok-0.0.28-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cantok-0.0.28.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for cantok-0.0.28.tar.gz
Algorithm Hash digest
SHA256 de8e40df058eb39842813f982889ed1fdc2376fd97601b132da60df38ab20b09
MD5 18ef2d2cbfa09a1f2bfb400e1b25c64a
BLAKE2b-256 474710e2a4126acbd94b8c19cc4fde4ad5bea3e3e01242c439ae3d88cd4d70ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cantok-0.0.28-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for cantok-0.0.28-py3-none-any.whl
Algorithm Hash digest
SHA256 6ba25e733607a5e36f32fe89b7e91870c2b8560254a1a02c60ef2651f5647fde
MD5 281e4a3da63e0ae6359289456daccf28
BLAKE2b-256 ea44302d6e4b4c6c0afe7f71d1432c2e37828c1061e73e64b9cc42cf084f6a8d

See more details on using hashes here.

Supported by

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