-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip: addressing issue #56, allowing for us to determine how often we caput #64
Draft
joshc-slac
wants to merge
6
commits into
master
Choose a base branch
from
joshc-slac/selective-caput-paradigm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e950b20
feat(timer): adding timer utility
joshc-slac 0e2f7e9
feat(ActionWorker, ActionNode, Timeout): moved wrapped_action_work to…
joshc-slac eb0dd13
pre-commit
joshc-slac 8b16696
wip
joshc-slac 6c507bb
wip: addressing issue #56
joshc-slac 9e7de8b
pre-commit
joshc-slac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import time | ||
|
||
|
||
class Timer(): | ||
def __init__(self, | ||
name: str, | ||
timer_period_seconds: float, | ||
auto_start: bool = False, | ||
is_periodic: bool = False): | ||
self.name = name | ||
self.timer_period_seconds = timer_period_seconds | ||
self.is_periodic = is_periodic | ||
self.auto_start = auto_start | ||
if (self.auto_start): | ||
self.timer_start_time = time.monotonic() | ||
else: | ||
self.timer_start_time = -1 | ||
|
||
def start_timer(self) -> None: | ||
self.timer_start_time = time.time() | ||
|
||
def check_valid_timer(self) -> bool: | ||
if (self.timer_start_time == -1): | ||
raise RuntimeError(f"{self.name} timer checked but not started") | ||
|
||
def is_elapsed(self) -> bool: | ||
elapsed = self.get_elapsed() | ||
if (elapsed > self.timer_period_seconds): | ||
if (self.is_periodic): | ||
self.timer_start_time = time.time() | ||
return True | ||
else: | ||
return False | ||
|
||
def get_elapsed(self) -> float: | ||
self.check_valid_timer() | ||
now = time.time() | ||
return now - self.timer_start_time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import time | ||
|
||
import pytest | ||
|
||
from beams.sequencer.helpers.Timer import Timer | ||
|
||
|
||
class TestTimer(): | ||
def test_elapsed(self): | ||
t = Timer(name="test_elapsed", | ||
timer_period_seconds=0.1, | ||
is_periodic=False) | ||
t.start_timer() | ||
assert t.is_elapsed() is False | ||
time.sleep(0.5) | ||
assert t.is_elapsed() is True | ||
|
||
def test_timer_error(self): | ||
t = Timer(name="test_error_not_started", | ||
timer_period_seconds=0.1, | ||
is_periodic=False) | ||
with pytest.raises(RuntimeError): | ||
t.get_elapsed() | ||
with pytest.raises(RuntimeError): | ||
t.is_elapsed() | ||
|
||
def test_periodic(self): | ||
t = Timer(name="test_error_not_started", | ||
timer_period_seconds=0.1, | ||
auto_start=True, | ||
is_periodic=True) | ||
time.sleep(0.2) | ||
assert t.is_elapsed() is True | ||
assert t.is_elapsed() is False | ||
time.sleep(0.1) | ||
assert t.is_elapsed() is True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this timer stuff probably makes the most sense living in the ActionNode, not the tree-item class. The purpose of the
*Item
here is to assist with serialization, and the*Node
does the actual work.We already did a bunch of work moving references away from the TreeItem into the ActionNode, it feels like a step backward to do so again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good point