Skip to content

Commit

Permalink
Merge pull request #27 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.22
  • Loading branch information
pomponchik authored Feb 23, 2024
2 parents 7d6fc84 + f0d73c2 commit 7c86ee3
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/ecosystem/about_ecosystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
We recommend adding token support to all your libraries where possible. If you have written such a project or added token support to an existing project, please let us know by writing an [issue](https://github.com/pomponchik/cantok/issues/new). If possible, information about the project will be added here.
13 changes: 13 additions & 0 deletions docs/ecosystem/projects/subprocess_management.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
To work with subprocesses, there is a [`suby`](https://github.com/pomponchik/suby) library with support for cancellation tokens. It has a very simple syntax:

```python
import suby

suby('python', '-c', 'print("hello, world!")')
```

A token can be passed as an argument:

```python
suby('python', '-c', 'import time; time.sleep(10_000)', token=TimeoutToken(1), catch_exceptions=True)
```
2 changes: 1 addition & 1 deletion docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ while token:
print(counter)
```

In this code, we use a token that describes several restrictions: on the [number of iterations](/types_of_tokens/CounterToken/) of the cycle, on [time](/types_of_tokens/TimeoutToken/), as well as on the [occurrence](/types_of_tokens/ConditionToken/) of a random unlikely event. When any of the indicated events occur, the cycle stops.
In this code, we use a token that describes several restrictions: on the [number of iterations](types_of_tokens/CounterToken.md) of the cycle, on [time](types_of_tokens/TimeoutToken.md), as well as on the [occurrence](types_of_tokens/ConditionToken.md) of a random unlikely event. When any of the indicated events occur, the cycle stops.

In fact, the library's capabilities are much broader, read the documentation below.
2 changes: 1 addition & 1 deletion docs/types_of_tokens/ConditionToken.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`ConditionToken` has superpower: it can check arbitrary conditions. In addition to this, it can do all the same things as [`SimpleToken`](/types_of_tokens/SimpleToken/). The condition is a function that returns an answer to the question "has the token been canceled" (`True`/`False`), it is passed to the token as the first required argument during initialization:
`ConditionToken` has superpower: it can check arbitrary conditions. In addition to this, it can do all the same things as [`SimpleToken`](../types_of_tokens/SimpleToken.md). The condition is a function that returns an answer to the question "has the token been canceled" (`True`/`False`), it is passed to the token as the first required argument during initialization:

```python
from cantok import ConditionToken
Expand Down
2 changes: 1 addition & 1 deletion docs/types_of_tokens/SimpleToken.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ print(repr(CounterToken(5) + TimeoutToken(5)))
# SimpleToken(CounterToken(5, direct=True), TimeoutToken(5, monotonic=False))
```

There is not much more to tell about it if you have read [the story](/what_are_tokens/in_general/) about tokens in general.
There is not much more to tell about it if you have read [the story](../what_are_tokens/in_general.md) about tokens in general.
2 changes: 1 addition & 1 deletion docs/what_are_tokens/cancel_and_read_the_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ token.cancel()
print(token.cancelled) # True
```

The cancelled attribute is dynamically calculated and takes into account, among other things, specific conditions that are checked by a specific token. Here is an example with a [token that measures time](/types_of_tokens/TimeoutToken/):
The cancelled attribute is dynamically calculated and takes into account, among other things, specific conditions that are checked by a specific token. Here is an example with a [token that measures time](../types_of_tokens/TimeoutToken.md):

```python
from time import sleep
Expand Down
8 changes: 4 additions & 4 deletions docs/what_are_tokens/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ token.check()

Each type of token has a corresponding type of exception that can be raised in this case:

- [`SimpleToken`](/types_of_tokens/SimpleToken/) -> `CancellationError`
- [`ConditionToken`](/types_of_tokens/ConditionToken/) -> `ConditionCancellationError`
- [`TimeoutToken`](/types_of_tokens/TimeoutToken/) -> `TimeoutCancellationError`
- [`CounterToken`](/types_of_tokens/CounterToken/) -> `CounterCancellationError`
- [`SimpleToken`](../types_of_tokens/SimpleToken.md) -> `CancellationError`
- [`ConditionToken`](../types_of_tokens/ConditionToken.md) -> `ConditionCancellationError`
- [`TimeoutToken`](../types_of_tokens/TimeoutToken.md) -> `TimeoutCancellationError`
- [`CounterToken`](../types_of_tokens/CounterToken.md) -> `CounterCancellationError`

When you call the `check()` method on any token, one of two things will happen. If it (or any of the tokens nested in it) was canceled by calling the `cancel()` method, `CancellationError` will always be raised. But if the cancellation occurred as a result of the unique ability of the token, such as for `TimeoutToken` - timeout expiration, then an exception specific to this type of token will be raised.

Expand Down
8 changes: 4 additions & 4 deletions docs/what_are_tokens/in_general.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ A token is an object that can tell you whether to continue the action you starte

There are 4 types of tokens in this library:

- [`SimpleToken`](/types_of_tokens/SimpleToken/)
- [`ConditionToken`](/types_of_tokens/ConditionToken/)
- [`TimeoutToken`](/types_of_tokens/TimeoutToken/)
- [`CounterToken`](/types_of_tokens/CounterToken/)
- [`SimpleToken`](../types_of_tokens/SimpleToken.md)
- [`ConditionToken`](../types_of_tokens/ConditionToken.md)
- [`TimeoutToken`](../types_of_tokens/TimeoutToken.md)
- [`CounterToken`](../types_of_tokens/CounterToken.md)

Each of them has its own characteristics, but they also have something in common:

Expand Down
2 changes: 1 addition & 1 deletion docs/what_are_tokens/summation.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Any tokens can be summed up among themselves. The summation operation generates another [`SimpleToken`](/types_of_tokens/SimpleToken/) that includes the previous 2:
Any tokens can be summed up among themselves. The summation operation generates another [`SimpleToken`](../types_of_tokens/SimpleToken.md) that includes the previous 2:

```python
from cantok import SimpleToken, TimeoutToken
Expand Down
2 changes: 1 addition & 1 deletion docs/what_are_tokens/waiting.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Yes, it looks like magic, it is magic. The method itself finds out how it was us

In addition to the above, the `wait()` method has two optional arguments:

- **`timeout`** (`int` or `float`) - the maximum waiting time in seconds. If this time is exceeded, a [`TimeoutCancellationError` exception](/what_are_tokens/waiting/) will be raised. By default, the `timeout` is not set.
- **`timeout`** (`int` or `float`) - the maximum waiting time in seconds. If this time is exceeded, a [`TimeoutCancellationError` exception](../what_are_tokens/waiting.md) will be raised. By default, the `timeout` is not set.
- **`step`** (`int` or `float`, by default `0.0001`) - the duration of the iteration, once in which the token state is polled, in seconds. For obvious reasons, you cannot set this value to a number that exceeds the `timeout`.
4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ nav:
- ConditionToken: types_of_tokens/ConditionToken.md
- TimeoutToken: types_of_tokens/TimeoutToken.md
- CounterToken: types_of_tokens/CounterToken.md
- Ecosystem:
- About the ecosystem: ecosystem/about_ecosystem.md
- Projects:
- Subprocess Management: ecosystem/projects/subprocess_management.md
markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "cantok"
version = "0.0.21"
version = "0.0.22"
authors = [
{ name="Evgeniy Blinov", email="[email protected]" },
]
Expand Down

0 comments on commit 7c86ee3

Please sign in to comment.