From 40ecd02cf513217511638f3231514d426f160ed2 Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Sun, 21 Apr 2024 14:40:08 +0300 Subject: [PATCH] readme --- README.md | 19 +++++++++++++++++++ metronomes/metronome.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1f0b0b..84cf93b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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! +``` diff --git a/metronomes/metronome.py b/metronomes/metronome.py index c024c87..6bc15c9 100644 --- a/metronomes/metronome.py +++ b/metronomes/metronome.py @@ -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]