From: Scott Gasch Date: Mon, 15 Aug 2022 16:20:20 +0000 (-0700) Subject: Fix a threading related bug in tplink_utils. X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=6ca1a7b51513673a7ae10ee38057e83aaee4c409;p=python_utils.git Fix a threading related bug in tplink_utils. --- diff --git a/decorator_utils.py b/decorator_utils.py index 438d7f9..4615fec 100644 --- a/decorator_utils.py +++ b/decorator_utils.py @@ -647,6 +647,13 @@ def timeout( main thread). When not using signals, timeout granularity will be rounded to the nearest 0.1s. + Beware that an @timeout on a function inside a module will be + evaluated at module load time and not when the wrapped function is + invoked. This can lead to problems when relying on the automatic + main thread detection code (use_signals=None, the default) since + the import probably happens on the main thread and the invocation + can happen on a different thread (which can't use signals). + Raises an exception when/if the timeout is reached. It is illegal to pass anything other than a function as the first diff --git a/smart_home/tplink_utils.py b/smart_home/tplink_utils.py index abf4970..ea35110 100644 --- a/smart_home/tplink_utils.py +++ b/smart_home/tplink_utils.py @@ -122,7 +122,7 @@ def decrypt(string: bytes) -> str: return result -@timeout(10, error_message="Timed out comunicating with device.") +@timeout(10, use_signals=False, error_message="Timed out comunicating with device.") def communicate_with_device( ip: str, port: int,