From 5fc9c1199b4190e31c8a03fe9db8bb6922f29504 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 1 Jun 2024 10:56:02 +0200 Subject: [PATCH] Fixed the root cause of the failure on the `time` module. The previous commit prompted a new error: ``` 2024-06-01 10:54:08,310|ERROR|platypush:plugin:bluetooth|module 'platypush.entities.time' has no attribute 'time' Traceback (most recent call last): File "/usr/lib/python3.9/dist-packages/platypush/plugins/__init__.py", line 247, in _runner self.main() File "/usr/lib/python3.9/dist-packages/platypush/plugins/bluetooth/__init__.py", line 590, in main self._refresh_cache() File "/usr/lib/python3.9/dist-packages/platypush/plugins/bluetooth/__init__.py", line 146, in _refresh_cache get_entities_engine().wait_start() File "/usr/lib/python3.9/dist-packages/platypush/entities/__init__.py", line 48, in get_entities_engine time_start = time.time() AttributeError: module 'platypush.entities.time' has no attribute 'time' ``` Which explains even the previous error: `import time` in that module won't use the `time` module from the Python library, but the `.time` module within the same directory. This error only happens when the current directory is part of PYTHONPATH (and usually it shouldn't), but for sake of keeping things safe I've replaced `time()` with `utcnow().timestamp()`, with `utcnow` imported from `platypush.utils`. --- platypush/entities/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platypush/entities/__init__.py b/platypush/entities/__init__.py index 49b818269..fa7ab1d00 100644 --- a/platypush/entities/__init__.py +++ b/platypush/entities/__init__.py @@ -1,8 +1,9 @@ import logging -import time from threading import Event from typing import Collection, Optional +from platypush.utils import utcnow + from ._base import ( Entity, EntityKey, @@ -45,8 +46,8 @@ def get_entities_engine(timeout: Optional[float] = None) -> EntitiesEngine: :param timeout: Timeout in seconds (default: None). """ - time_start = time.time() - while not timeout or (time.time() - time_start < timeout): + time_start = utcnow().timestamp() + while not timeout or (utcnow().timestamp() - time_start < timeout): if _engine: break