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.
Source Distribution
cancel_token-0.1.6.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file cancel_token-0.1.6.tar.gz
.
File metadata
- Download URL: cancel_token-0.1.6.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c06b5f4a8810ac71c95cd9705c03b0fdd441f366687275c869dcac113a0e843b |
|
MD5 | b34d1e4ad804b33ca317f8e0d5f6f1f2 |
|
BLAKE2b-256 | bd10ea94ef5422aa36500698f9d76a7f749d77cba7c721f9fc59ef0122fc377e |
File details
Details for the file cancel_token-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: cancel_token-0.1.6-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4667fa12be561a4c4229b242cfa8916c740ad1b0b866dfceeafc0245e0f5680b |
|
MD5 | 1fc5c8a54c25679f6a68774bb121972e |
|
BLAKE2b-256 | 5ff25f619de61d7dc8e1db19c2955c09310579ae6f2473c418a2456fe860ee04 |