Skip to main content

Simple CancellationToken

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for cancel-token, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size cancel_token-0.1.5-py3-none-any.whl (3.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size cancel_token-0.1.5.tar.gz (2.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page