Skip to content

Commit de9ce6a

Browse files
authored
Merge pull request #20 from Code-Partners/feat-nanotime
Feat nanotime
2 parents 5e0384d + 16e3a1d commit de9ce6a

File tree

5 files changed

+6
-22
lines changed

5 files changed

+6
-22
lines changed

common/clock.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class Clock:
66
@staticmethod
77
def now() -> int:
8-
current_time_millis = time.time() * 1000
9-
local_timezone_offset_millis = datetime.now(timezone.utc).astimezone().utcoffset().total_seconds() * 1000
10-
current_time_micros = int((current_time_millis + local_timezone_offset_millis) * 1000)
8+
current_time_micros = time.time_ns() / 1e3
9+
local_timezone_offset_micros = datetime.now(timezone.utc).astimezone().utcoffset().total_seconds() * 1e6
10+
current_time_micros = int(current_time_micros + local_timezone_offset_micros)
1111
return current_time_micros

common/clock_resolution.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

protocols/cloud/chunk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ def milliseconds_since_the_first_packet(self) -> int:
6060

6161
@staticmethod
6262
def _get_nano_time() -> int:
63-
return int(time.perf_counter() * 1e9)
63+
return int(time.perf_counter_ns())

protocols/protocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def _reset(self):
218218
try:
219219
self._internal_disconnect()
220220
finally:
221-
self.__reconnect_tick_count = time.time() * 1000
221+
self.__reconnect_tick_count = time.time_ns() / 1e6
222222

223223
def _impl_disconnect(self):
224224
if self._connected:
@@ -417,7 +417,7 @@ def __forward_packet(self, packet: Packet, disconnect: bool) -> None:
417417

418418
def __do_reconnect(self) -> None:
419419
if self.__reconnect_interval > 0:
420-
tick_count = time.time() * 1000
420+
tick_count = time.time_ns() / 1e6
421421
if tick_count - self.__reconnect_tick_count < self.__reconnect_interval:
422422
return
423423

smartinspect.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import typing
44

55
from common.clock import Clock
6-
from common.clock_resolution import ClockResolution
76
from common.events.connections_parser_event import ConnectionsParserEvent
87
from common.events.control_command_event import ControlCommandEvent
98
from common.events.error_event import ErrorEvent
@@ -51,7 +50,6 @@ def __init__(self, appname: str):
5150
self.__hostname = self.__obtain_hostname()
5251
self.__listeners = LockedSet()
5352
self.__sessions = SessionManager()
54-
self.__resolution = ClockResolution.STANDARD
5553
self.__variables = ProtocolVariables()
5654

5755
self.__is_multithreaded = False
@@ -61,13 +59,6 @@ def __init__(self, appname: str):
6159
def now() -> int:
6260
return Clock.now()
6361

64-
def get_resolution(self) -> ClockResolution:
65-
return self.__resolution
66-
67-
def set_resolution(self, resolution: ClockResolution) -> None:
68-
if isinstance(resolution, ClockResolution):
69-
self.__resolution = resolution
70-
7162
@classmethod
7263
def get_version(cls) -> str:
7364
return cls.__VERSION

0 commit comments

Comments
 (0)