-
Notifications
You must be signed in to change notification settings - Fork 49
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
Use threads instead of processes in test_pocs.py #468
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import re | ||
import shutil | ||
import subprocess | ||
|
||
import time | ||
|
||
from astropy import units as u | ||
from astropy.coordinates import AltAz | ||
|
@@ -48,6 +48,42 @@ def flatten_time(t): | |
return t.isot.replace('-', '').replace(':', '').split('.')[0] | ||
|
||
|
||
# This is a streamlined variant of PySerial's serialutil.Timeout. | ||
class Timeout(object): | ||
"""Simple timer object for tracking whether a time duration has elapsed. | ||
|
||
Attribute `is_non_blocking` is true IFF the duration is zero. | ||
""" | ||
|
||
def __init__(self, duration): | ||
"""Initialize a timeout with given duration (seconds).""" | ||
assert duration >= 0 | ||
self.is_non_blocking = (duration == 0) | ||
self.duration = duration | ||
self.restart() | ||
|
||
def expired(self): | ||
"""Return a boolean, telling if the timeout has expired.""" | ||
return self.time_left() <= 0 | ||
|
||
def time_left(self): | ||
"""Return how many seconds are left until the timeout expires.""" | ||
if self.is_non_blocking: | ||
return 0 | ||
else: | ||
delta = self.target_time - time.monotonic() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I missing something about where these come from? Should this class inherit from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to just copy their code and eliminate things we don't need. time.monotonic() is like time.time(), but guarantees that it won't go backwards. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I didn't realize There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although maybe just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. restart because init calls it, so that it is started at creation. If too confusing, I could remove restart, so you have to create a new instance each time, which is definitely the common way to use it. |
||
if delta > self.duration: | ||
# clock jumped, recalculate | ||
self.restart() | ||
return self.duration | ||
else: | ||
return max(0, delta) | ||
|
||
def restart(self): | ||
"""Restart the timed duration.""" | ||
self.target_time = time.monotonic() + self.duration | ||
|
||
|
||
def listify(obj): | ||
""" Given an object, return a list | ||
|
||
|
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 don't understand where non-blocking case. Where would you be using a timeout=0?
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.
Yes, timeout==0 means that it will always be considered to have expired.