The SocketScience.check_recent_pings class method has the following definition:
@classmethod
def check_recent_pings(cls):
recent = cls._pings.sort(key=lambda p: p["timestamp"]).reverse() # 1
if len(recent) >= 1:
most_recent = recent[0]["timestamp"]
now = time.time()
if now - most_recent >= 90 or len(recent) == 0: # 2
# No active Smokeys. Wait a random number of seconds, then switch to active.
sleep = random.randint(0, 30)
cls._switch_task = Tasks.later(SocketScience.switch_to_active, after=sleep)
I'm pretty sure this has two bugs on the marked lines:
sort is in-place and returns None; the reversal should probably be a different line.
- The
len check is too late to short-circuit the now check.
If there are no objections, I'm happy to fix both.
The
SocketScience.check_recent_pingsclass method has the following definition:I'm pretty sure this has two bugs on the marked lines:
sortis in-place and returnsNone; the reversal should probably be a different line.lencheck is too late to short-circuit thenowcheck.If there are no objections, I'm happy to fix both.