Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pomponchik committed Apr 21, 2024
1 parent 0f238ea commit 40ecd02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This library offers the easiest way to run regular tasks. Just give it a functio
- [**Logging**](#logging)
- [**Error escaping**](#error-escaping)
- [**Working with Cancellation Tokens**](#working-with-cancellation-tokens)
- [**Limitations**](#limitations)


## Quick start
Expand Down Expand Up @@ -178,3 +179,21 @@ sleep(1.5) # Here I specify a little more time than in the constructor of the t
print(metronome.stopped)
#> True
```


## Limitations

You can limit the total running time of the metronome by setting the `duration` value (in seconds):

```python
from time import sleep
from metronomes import Metronome

metronome = Metronome(0.2, lambda: print('go!'), duration=0.6)

metronome.start()
sleep(1)
#> go!
#> go!
#> go!
```
2 changes: 1 addition & 1 deletion metronomes/metronome.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def stop(self) -> None:
if not self.started:
raise StopNotStartedMetronomeError("You can't stop a metronome that hasn't been started yet.")
elif self.stopped:
raise StopStoppedMetronomeError("You've already stopped this metronome, it's impossible to do it twice.")
raise StopStoppedMetronomeError("You've already stopped this metronome (or it was canceled on its own, for example, when the limit expired), it's impossible to do it twice.")

self.token.cancel()
self.thread.join() # type: ignore[union-attr]
Expand Down

0 comments on commit 40ecd02

Please sign in to comment.