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

Uploaded Source

Built Distribution

cantok-0.0.25-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cantok-0.0.25.tar.gz
  • Upload date:
  • Size: 8.0 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.25.tar.gz
Algorithm Hash digest
SHA256 ff2e09ac609df9b4d1289727cbbf7c19aece61e041a31e00b60aebb025a971d7
MD5 49efb56404b2c59fd316047686ed369c
BLAKE2b-256 cc531d0cd31f6193961e8a50996f54bcad8bbdfc004bab87d96f5e64aa6c1efe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cantok-0.0.25-py3-none-any.whl
  • Upload date:
  • Size: 9.5 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.25-py3-none-any.whl
Algorithm Hash digest
SHA256 cc711b266920735f856199503cb8fc2a2a176567e0be04b2a4658e9f8e46f2b1
MD5 be4f1705d8780aa98563325c55b28f71
BLAKE2b-256 cdd9c3ffacef542ce6a2b6d448beb747233d23dc02fd4055946b022f6b2103b5

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