cantok


Namecantok JSON
Version 0.0.31 PyPI version JSON
download
home_pageNone
SummaryImplementation of the "Cancellation Token" pattern
upload_time2024-08-27 11:12:16
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords cancellation tokens parallel programming concurrency
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![logo](https://raw.githubusercontent.com/pomponchik/cantok/main/docs/assets/logo_5.png)

[![Downloads](https://static.pepy.tech/badge/cantok/month)](https://pepy.tech/project/cantok)
[![Downloads](https://static.pepy.tech/badge/cantok)](https://pepy.tech/project/cantok)
[![codecov](https://codecov.io/gh/pomponchik/cantok/graph/badge.svg?token=eZ4eK6fkmx)](https://codecov.io/gh/pomponchik/cantok)
[![Lines of code](https://sloc.xyz/github/pomponchik/cantok/?category=code)](https://github.com/boyter/scc/)
[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/cantok?branch=main)](https://hitsofcode.com/github/pomponchik/cantok/view?branch=main)
[![Test-Package](https://github.com/pomponchik/cantok/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/cantok/actions/workflows/tests_and_coverage.yml)
[![Python versions](https://img.shields.io/pypi/pyversions/cantok.svg)](https://pypi.python.org/pypi/cantok)
[![PyPI version](https://badge.fury.io/py/cantok.svg)](https://badge.fury.io/py/cantok)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)


Cancellation Token is a pattern that allows us to refuse to continue calculations that we no longer need. It is implemented out of the box in many programming languages, for example in [C#](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken) and in [Go](https://pkg.go.dev/context). However, there was still no sane implementation in Python, until the [cantok](https://github.com/pomponchik/cantok) library appeared.


## Quick start

Install [it](https://pypi.org/project/cantok/):

```bash
pip install cantok
```

And use:

```python
from random import randint
from cantok import ConditionToken, CounterToken, TimeoutToken

token = ConditionToken(lambda: randint(1, 100_000) == 1984) + CounterToken(400_000, direct=False) + TimeoutToken(1)
counter = 0

while token:
  counter += 1

print(counter)
```

Read more in the [documentation](https://cantok.readthedocs.io/en/latest/)!

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cantok",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "cancellation tokens, parallel programming, concurrency",
    "author": null,
    "author_email": "Evgeniy Blinov <zheni-b@yandex.ru>",
    "download_url": "https://files.pythonhosted.org/packages/1b/71/67dc7fe9632e0cd21c7675d329b6a44c268392e09c83eb31fd9d52662c79/cantok-0.0.31.tar.gz",
    "platform": null,
    "description": "![logo](https://raw.githubusercontent.com/pomponchik/cantok/main/docs/assets/logo_5.png)\n\n[![Downloads](https://static.pepy.tech/badge/cantok/month)](https://pepy.tech/project/cantok)\n[![Downloads](https://static.pepy.tech/badge/cantok)](https://pepy.tech/project/cantok)\n[![codecov](https://codecov.io/gh/pomponchik/cantok/graph/badge.svg?token=eZ4eK6fkmx)](https://codecov.io/gh/pomponchik/cantok)\n[![Lines of code](https://sloc.xyz/github/pomponchik/cantok/?category=code)](https://github.com/boyter/scc/)\n[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/cantok?branch=main)](https://hitsofcode.com/github/pomponchik/cantok/view?branch=main)\n[![Test-Package](https://github.com/pomponchik/cantok/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/cantok/actions/workflows/tests_and_coverage.yml)\n[![Python versions](https://img.shields.io/pypi/pyversions/cantok.svg)](https://pypi.python.org/pypi/cantok)\n[![PyPI version](https://badge.fury.io/py/cantok.svg)](https://badge.fury.io/py/cantok)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\n\nCancellation Token is a pattern that allows us to refuse to continue calculations that we no longer need. It is implemented out of the box in many programming languages, for example in [C#](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken) and in [Go](https://pkg.go.dev/context). However, there was still no sane implementation in Python, until the [cantok](https://github.com/pomponchik/cantok) library appeared.\n\n\n## Quick start\n\nInstall [it](https://pypi.org/project/cantok/):\n\n```bash\npip install cantok\n```\n\nAnd use:\n\n```python\nfrom random import randint\nfrom cantok import ConditionToken, CounterToken, TimeoutToken\n\ntoken = ConditionToken(lambda: randint(1, 100_000) == 1984) + CounterToken(400_000, direct=False) + TimeoutToken(1)\ncounter = 0\n\nwhile token:\n  counter += 1\n\nprint(counter)\n```\n\nRead more in the [documentation](https://cantok.readthedocs.io/en/latest/)!\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Implementation of the \"Cancellation Token\" pattern",
    "version": "0.0.31",
    "project_urls": {
        "Documentation": "http://cantok.readthedocs.io/",
        "Source": "https://github.com/pomponchik/cantok",
        "Tracker": "https://github.com/pomponchik/cantok/issues"
    },
    "split_keywords": [
        "cancellation tokens",
        " parallel programming",
        " concurrency"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1c6d21e00a0fb8230cdcab9ef0b36b309493a9659e13522a26a3fe9a1c20def5",
                "md5": "4ad65c69439fa0457f6cc3088c9c8d66",
                "sha256": "02c225fc079dbd9b367224bb85c5722789313f3036f9b3b82c9117af252fdc15"
            },
            "downloads": -1,
            "filename": "cantok-0.0.31-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4ad65c69439fa0457f6cc3088c9c8d66",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 11915,
            "upload_time": "2024-08-27T11:12:15",
            "upload_time_iso_8601": "2024-08-27T11:12:15.304435Z",
            "url": "https://files.pythonhosted.org/packages/1c/6d/21e00a0fb8230cdcab9ef0b36b309493a9659e13522a26a3fe9a1c20def5/cantok-0.0.31-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1b7167dc7fe9632e0cd21c7675d329b6a44c268392e09c83eb31fd9d52662c79",
                "md5": "4cc88894b29f6e318a44f02ab72713bf",
                "sha256": "8e53220fae103a6e103623a3079ddd19cd52f7c6538f7034b31f34660486a2dc"
            },
            "downloads": -1,
            "filename": "cantok-0.0.31.tar.gz",
            "has_sig": false,
            "md5_digest": "4cc88894b29f6e318a44f02ab72713bf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9422,
            "upload_time": "2024-08-27T11:12:16",
            "upload_time_iso_8601": "2024-08-27T11:12:16.728146Z",
            "url": "https://files.pythonhosted.org/packages/1b/71/67dc7fe9632e0cd21c7675d329b6a44c268392e09c83eb31fd9d52662c79/cantok-0.0.31.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-27 11:12:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pomponchik",
    "github_project": "cantok",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cantok"
}
        
Elapsed time: 0.41056s