{"id":13492559,"url":"https://github.com/pomponchik/cantok","last_synced_at":"2025-03-28T10:32:25.552Z","repository":{"id":195788007,"uuid":"693321863","full_name":"pomponchik/cantok","owner":"pomponchik","description":"Implementation of the \"Cancellation Token\" pattern","archived":false,"fork":false,"pushed_at":"2025-03-01T20:16:22.000Z","size":1198,"stargazers_count":117,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-01T20:23:12.944Z","etag":null,"topics":["cancellationtoken","threading","threading-synchronization"],"latest_commit_sha":null,"homepage":"http://cantok.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pomponchik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-18T19:46:50.000Z","updated_at":"2025-02-21T21:53:41.000Z","dependencies_parsed_at":"2023-10-02T19:25:34.693Z","dependency_job_id":"3034481a-507d-4aa9-98d3-aa78d6b69c11","html_url":"https://github.com/pomponchik/cantok","commit_stats":null,"previous_names":["pomponchik/ctok","pomponchik/cantok"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pomponchik%2Fcantok","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pomponchik%2Fcantok/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pomponchik%2Fcantok/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pomponchik%2Fcantok/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pomponchik","download_url":"https://codeload.github.com/pomponchik/cantok/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246012640,"owners_count":20709485,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cancellationtoken","threading","threading-synchronization"],"created_at":"2024-07-31T19:01:07.099Z","updated_at":"2025-03-28T10:32:24.812Z","avatar_url":"https://github.com/pomponchik.png","language":"Python","readme":"![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","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpomponchik%2Fcantok","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpomponchik%2Fcantok","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpomponchik%2Fcantok/lists"}