From 56babb011b73137dc62b3ccdd72e96c1fb188a31 Mon Sep 17 00:00:00 2001 From: Oliver Ebert Date: Thu, 31 May 2018 22:14:51 +0200 Subject: [PATCH 1/6] Use a monotonic clock for WebsocketSession's session_time This will try to use the facilities provided by module monotonic. If the import fails we'll fall back on using time.time() as before. --- lomond/session.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lomond/session.py b/lomond/session.py index 5d32acd..dc9f103 100644 --- a/lomond/session.py +++ b/lomond/session.py @@ -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: + from time import time as monotonic_time + from .frame import Frame from . import errors from . import events @@ -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): @@ -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.""" From 236afa8cc1932e6dd2a78eb2257fa7bc038985d1 Mon Sep 17 00:00:00 2001 From: Oliver Ebert Date: Wed, 6 Jun 2018 21:54:38 +0200 Subject: [PATCH 2/6] Explicitly catch only ImportError when importing monotonic --- lomond/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lomond/session.py b/lomond/session.py index dc9f103..a712a7e 100644 --- a/lomond/session.py +++ b/lomond/session.py @@ -18,7 +18,7 @@ try: from monotonic import monotonic as monotonic_time -except: +except ImportError: from time import time as monotonic_time from .frame import Frame From 36397f3dd0e131b065166fc9a33f94a1fad1e058 Mon Sep 17 00:00:00 2001 From: Oliver Ebert Date: Wed, 6 Jun 2018 21:56:43 +0200 Subject: [PATCH 3/6] Rename monotonic_time to get_time --- lomond/session.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lomond/session.py b/lomond/session.py index a712a7e..58fd6df 100644 --- a/lomond/session.py +++ b/lomond/session.py @@ -17,9 +17,9 @@ from six.moves.urllib.parse import urlparse try: - from monotonic import monotonic as monotonic_time + from monotonic import monotonic as get_time except ImportError: - from time import time as monotonic_time + from time import time as get_time from .frame import Frame from . import errors @@ -64,7 +64,7 @@ def session_time(self): return ( 0.0 if self._start_time is None else - monotonic_time() - self._start_time + get_time() - self._start_time ) def close(self): @@ -325,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 = monotonic_time() + self._start_time = get_time() def _on_event(self, event, auto_pong=True): """Handle logic in response to an event.""" From 4d61e75ee8554af1dbd53718ea4fae0eb2bc3da9 Mon Sep 17 00:00:00 2001 From: Oliver Ebert Date: Thu, 7 Jun 2018 22:44:26 +0200 Subject: [PATCH 4/6] Make monotonic a mandatory requirement and adjust import --- lomond/session.py | 9 +++------ setup.py | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lomond/session.py b/lomond/session.py index 58fd6df..41c0fb1 100644 --- a/lomond/session.py +++ b/lomond/session.py @@ -16,10 +16,7 @@ from six.moves.urllib.parse import urlparse -try: - from monotonic import monotonic as get_time -except ImportError: - from time import time as get_time +from monotonic import monotonic as monotonic_time from .frame import Frame from . import errors @@ -64,7 +61,7 @@ def session_time(self): return ( 0.0 if self._start_time is None else - get_time() - self._start_time + monotonic_time() - self._start_time ) def close(self): @@ -325,7 +322,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 = get_time() + self._start_time = monotonic_time() def _on_event(self, event, auto_pong=True): """Handle logic in response to an event.""" diff --git a/setup.py b/setup.py index 1282454..b5d6e4b 100644 --- a/setup.py +++ b/setup.py @@ -37,6 +37,7 @@ setup_requires=['pytest-runner'], tests_require=['pytest'], install_requires=[ + 'monotonic>=1.5', 'six>=1.10.0', ], zip_safe=True From 2787a7fb426940a2fbd3d8d616e44c60b4ba0f05 Mon Sep 17 00:00:00 2001 From: Oliver Ebert Date: Sat, 23 Jun 2018 16:51:47 +0200 Subject: [PATCH 5/6] Set ignore_outcome=true for tox testenv:coverage This should fix the CircleCI issue. --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 72d6b28..64015ff 100644 --- a/tox.ini +++ b/tox.ini @@ -40,3 +40,4 @@ commands = coverage html -d {env:CIRCLE_ARTIFACTS:reports}/combined coverage report coveralls +ignore_outcome = true From fed91ef14f61b31e74d680ceb4b1000e79f0d384 Mon Sep 17 00:00:00 2001 From: Oliver Ebert Date: Mon, 25 Jun 2018 23:19:36 +0200 Subject: [PATCH 6/6] Fix duplicate name 'ignore_outcome' in tox.ini --- tox.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/tox.ini b/tox.ini index 94e6e88..82ba67d 100644 --- a/tox.ini +++ b/tox.ini @@ -41,4 +41,3 @@ commands = coverage html -d {env:CIRCLE_ARTIFACTS:reports}/combined coverage report coveralls -ignore_outcome = true