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.1.tar.gz
(5.0 kB
view hashes)
Built Distribution
Close
Hashes for cancel_contexts-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7da99976f3c24a3af5af348ad6b73f67de9b07d9fd3f065ba445734ac3111860 |
|
MD5 | bab45b1a36dc81c3a9fa6c2a8c6efbdc |
|
BLAKE2b-256 | 696a5ba7c054d30ccd440ade56d54d9113292382ea8edbe24f000b1383c37d38 |