cancel-contexts


Namecancel-contexts JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/alpden550/cancel-contexts
SummaryRealisation for canceling contexts (cancelled tokens) for Python
upload_time2024-05-10 05:25:04
maintainerNone
docs_urlNone
authorDenis Novikov
requires_python<4.0,>=3.11
licenseMIT
keywords python python3 cancel token cancel context
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash 
poetry add cancel-contexts
```

or

```bash
pip install cancel-contexts
```


## Usage

```python
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
```

```python
from cancel_contexts import CancelContext
from cancel_contexts.exceptions import ContextCancelledError

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

print(ctx.cancelled) # True

try:
    ctx.check_cancelled()
except ContextCancelledError as e:
    print(e) # Context was cancelled
```


```python
from time import sleep
from cancel_contexts import TimeOutContext
from cancel_contexts.exceptions import ContextTimeOutError

ctx = TimeOutContext(10)

print(ctx.cancelled) # False

while ctx:
    sleep(1)
    print(ctx.cancelled) # False

print(ctx.cancelled) # True
try:
    ctx.check_cancelled()
except ContextTimeOutError as e:
    print(e) # Context was timed out
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alpden550/cancel-contexts",
    "name": "cancel-contexts",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": "python, python3, cancel token, cancel context",
    "author": "Denis Novikov",
    "author_email": "alpden550@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b0/e6/ddebd7fae55019a2f675504514ec3fb67061878d58cb5e153e9cfa239d9b/cancel_contexts-0.1.3.tar.gz",
    "platform": null,
    "description": "# Cancel-contexts\n\nThis is a simple implementation of cancel-contexts (cancel tokens is C#) in Python. It is inspired by the Go programming language's context package.\n\n## Installation\n\n```bash \npoetry add cancel-contexts\n```\n\nor\n\n```bash\npip install cancel-contexts\n```\n\n\n## Usage\n\n```python\nfrom cancel_contexts import CancelContext\n\nctx = CancelContext()\nprint(ctx.cancelled) # False\nprint(bool(ctx)) # True\n\nctx.cancel()\nprint(ctx.cancelled) # True\nprint(bool(ctx)) # False\n```\n\n```python\nfrom cancel_contexts import CancelContext\nfrom cancel_contexts.exceptions import ContextCancelledError\n\nctx = CancelContext()\ncounter = 0\nwhile ctx:\n    counter += 1\n    if counter == 10:\n        ctx.cancel()\n\nprint(ctx.cancelled) # True\n\ntry:\n    ctx.check_cancelled()\nexcept ContextCancelledError as e:\n    print(e) # Context was cancelled\n```\n\n\n```python\nfrom time import sleep\nfrom cancel_contexts import TimeOutContext\nfrom cancel_contexts.exceptions import ContextTimeOutError\n\nctx = TimeOutContext(10)\n\nprint(ctx.cancelled) # False\n\nwhile ctx:\n    sleep(1)\n    print(ctx.cancelled) # False\n\nprint(ctx.cancelled) # True\ntry:\n    ctx.check_cancelled()\nexcept ContextTimeOutError as e:\n    print(e) # Context was timed out\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Realisation for canceling contexts (cancelled tokens) for Python",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/alpden550/cancel-contexts",
        "Repository": "https://github.com/alpden550/cancel-contexts"
    },
    "split_keywords": [
        "python",
        " python3",
        " cancel token",
        " cancel context"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eda2d2e45426a695584e2f320e7acd14e02c5c4c0e51a1c447c12970d10cd760",
                "md5": "31d36b23ffa4e5a26c54866bf8616c43",
                "sha256": "12e1a33dc646651817819de91e5b45dd7c4f5eb3658c8570d0375073172c1f58"
            },
            "downloads": -1,
            "filename": "cancel_contexts-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "31d36b23ffa4e5a26c54866bf8616c43",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 5146,
            "upload_time": "2024-05-10T05:25:03",
            "upload_time_iso_8601": "2024-05-10T05:25:03.013470Z",
            "url": "https://files.pythonhosted.org/packages/ed/a2/d2e45426a695584e2f320e7acd14e02c5c4c0e51a1c447c12970d10cd760/cancel_contexts-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0e6ddebd7fae55019a2f675504514ec3fb67061878d58cb5e153e9cfa239d9b",
                "md5": "4ccc35f0cbba20be859cdfec048626af",
                "sha256": "ba330ebb67ba2169cba15f72d7c50638c6a250cae16dbdd9e86f0f1b5ca6863c"
            },
            "downloads": -1,
            "filename": "cancel_contexts-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "4ccc35f0cbba20be859cdfec048626af",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 3537,
            "upload_time": "2024-05-10T05:25:04",
            "upload_time_iso_8601": "2024-05-10T05:25:04.712906Z",
            "url": "https://files.pythonhosted.org/packages/b0/e6/ddebd7fae55019a2f675504514ec3fb67061878d58cb5e153e9cfa239d9b/cancel_contexts-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-10 05:25:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alpden550",
    "github_project": "cancel-contexts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cancel-contexts"
}
        
Elapsed time: 0.91671s