Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cancel-token

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cancel-token

Simple CancellationToken

  • 0.1.6
  • PyPI
  • Socket score

Maintainers
1

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc