|
1 | 1 | import threading
|
2 |
| -from datetime import datetime |
| 2 | +import time |
3 | 3 |
|
4 | 4 | from rosbridge_library.capability import Capability
|
5 | 5 |
|
@@ -84,13 +84,13 @@ def __init__(self, protocol):
|
84 | 84 | # 4.b) pass the reconstructed message string to protocol.incoming() # protocol.incoming is checking message fields by itself, so no need to do this before passing the reconstructed message to protocol
|
85 | 85 | # 4.c) remove the fragment list to free up memory
|
86 | 86 | def defragment(self, message):
|
87 |
| - now = datetime.now() |
| 87 | + now = time.monotonic() |
88 | 88 |
|
89 | 89 | if self.received_fragments is not None:
|
90 | 90 | for id in self.received_fragments.keys():
|
91 | 91 | time_diff = now - self.received_fragments[id]["timestamp_last_append"]
|
92 | 92 | if (
|
93 |
| - time_diff.total_seconds() > self.fragment_timeout |
| 93 | + time_diff > self.fragment_timeout |
94 | 94 | and not self.received_fragments[id]["is_reconstructing"]
|
95 | 95 | ):
|
96 | 96 | log_msg = ["fragment list ", str(id), " timed out.."]
|
@@ -188,15 +188,15 @@ def defragment(self, message):
|
188 | 188 | log_msg = "".join(log_msg)
|
189 | 189 | self.protocol.log("debug", log_msg)
|
190 | 190 |
|
191 |
| - duration = datetime.now() - now |
| 191 | + duration = time.monotonic() - now |
192 | 192 |
|
193 | 193 | # Pass the reconstructed message to rosbridge
|
194 | 194 | self.protocol.incoming(reconstructed_msg)
|
195 | 195 | log_msg = ["reconstructed message (ID:" + str(msg_id) + ") from "]
|
196 | 196 | log_msg.extend([str(msg_total), " fragments. "])
|
197 | 197 | # cannot access msg.data if message is a service_response or else!
|
198 | 198 | # log_msg += "[message length: " + str(len(str(json.loads(reconstructed_msg)["msg"]["data"]))) +"]"
|
199 |
| - log_msg.extend(["[duration: ", str(duration.total_seconds()), " s]"]) |
| 199 | + log_msg.extend(["[duration: ", str(duration), " s]"]) |
200 | 200 | log_msg = "".join(log_msg)
|
201 | 201 | self.protocol.log("info", log_msg)
|
202 | 202 |
|
|
0 commit comments