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.2.tar.gz
(2.5 kB
view hashes)
Built Distribution
Close
Hashes for cancel_contexts-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed23b570ee80d2798dbb6c755178ac8284f4e0f3103fa062f6e40080b5a5ad17 |
|
MD5 | cb60ab801e3b265c9a936449a8ec544e |
|
BLAKE2b-256 | fc4551b92aaf05a769cf548913bcb7b0e62a45d44d0337838b9423481f482b5b |