Skip to main content

Realisation for canceling contexts (cancelled tokens) for Python

Project description

Cancel-contexts

This is a simple implementation of cancel-contexts (cancel tokens is C#) in Python. It is inspired by the Go programming language's context package.

Installation

poetry add cancel-contexts

or

pip install cancel-contexts

Usage

from cancel_contexts import CancelContext

ctx = CancelContext()
print(ctx.cancelled) # False
print(bool(ctx)) # True

ctx.cancel()
print(ctx.cancelled) # True
print(bool(ctx)) # False
from cancel_contexts import CancelContext

ctx = CancelContext()
counter = 0
while ctx:
    counter += 1
    if counter == 10:
        ctx.cancel()

print(ctx.cancelled) # True

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

cancel_contexts-0.1.0.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

cancel_contexts-0.1.0-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

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