Skip to content
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 a monotonic clock for WebsocketSession's session_time #64

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
10 changes: 7 additions & 3 deletions lomond/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
import socket
import ssl
import threading
import time

from six.moves.urllib.parse import urlparse

try:
from monotonic import monotonic as monotonic_time
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to explicitly catch an ImportError in the off chance the module has any import time side-effects.

from time import time as monotonic_time
Copy link
Contributor

@willmcgugan willmcgugan Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its imported this way, it's not strictly monotonic time. Suggest calling it get_time (for both).


from .frame import Frame
from . import errors
from . import events
Expand Down Expand Up @@ -60,7 +64,7 @@ def session_time(self):
return (
0.0
if self._start_time is None else
time.time() - self._start_time
monotonic_time() - self._start_time
)

def close(self):
Expand Down Expand Up @@ -321,7 +325,7 @@ def _on_ready(self):
"""Called when a ready event is received."""
self._last_pong = 0.0
self._next_ping = 0.0
self._start_time = time.time()
self._start_time = monotonic_time()

def _on_event(self, event, auto_pong=True):
"""Handle logic in response to an event."""
Expand Down