Skip to main content

CancellationToken for Python

This library provide simple cancellation token.

Usage

First create token

from cancel_token import CancellationToken

token = CancellationToken()

At any point in time you can check if token has been cancelled:

if token.cancelled:
    print('Operation already cancelled')
    return None  

To cancel token call its cancel method:

token.cancel()
assert token.cancelled

It is also possible to add callbacks that will be called on when token is cancelled:

def handler():
    print('Operation has been cancelled')

token.on_cancel(handler)

Note:

  • If token is already cancelled, callback will be invoked immediately.
  • All registered callbacks will be called sequentially during cancel call.
  • Callback throwing exception will prevent remaining callbacks from calling. However token will be cancelled
  • During callback invocation token is already cancelled
  • It is possible to add callback from within callback
  • Removing callback from within callback will not prevent its execution

Release files for cancel-token 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cancel-token 0.1.6
File Size Uploaded
cancel_token-0.1.6.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cancel-token 0.1.6
File Interpreter ABI Platform
cancel_token-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / cancel_token-0.1.6.tar.gz

Download URL cancel_token-0.1.6.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c06b5f4a8810ac71c95cd9705c03b0fdd441f366687275c869dcac113a0e843b
BLAKE2b-256 checksum
How to use checksums
bd10ea94ef5422aa36500698f9d76a7f749d77cba7c721f9fc59ef0122fc377e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.5

Release files / cancel_token-0.1.6-py3-none-any.whl

Download URL cancel_token-0.1.6-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4667fa12be561a4c4229b242cfa8916c740ad1b0b866dfceeafc0245e0f5680b
BLAKE2b-256 checksum
How to use checksums
5ff25f619de61d7dc8e1db19c2955c09310579ae6f2473c418a2456fe860ee04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

3 release files

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page