bindings: python: change the interpretation of None in event wait
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 23 May 2023 13:29:29 +0000 (15:29 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 24 May 2023 09:12:49 +0000 (11:12 +0200)
The docs don't mention it but currently passing None as the timeout to
one of the event wait methods works like passing 0 to select() - the wait
method returns immediately. Change it to a more standard behavior - None
makes the method block indefinitely until an event becomes available for
reading.

This is a slight change in the behavior but let's hope nobody complains
as libgpiod v2 is still pretty recent and its adoption is (hopegully)
not wide-spread yet.

Reported-by: Nicolas Frattaroli <frattaroli.nicolas@gmail.com>
Suggested-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
bindings/python/gpiod/chip.py
bindings/python/gpiod/internal.py
bindings/python/gpiod/line_request.py

index 97ff340cd77fbb5dae48a5d05cf6aaaf4754556b..52d0757efb0641d597d9e3b998f66a867fbcdd75 100644 (file)
@@ -195,7 +195,8 @@ class Chip:
         Args:
           timeout:
             Wait time limit represented as either a datetime.timedelta object
-            or the number of seconds stored in a float.
+            or the number of seconds stored in a float. If set to 0, the
+            method returns immediately, if set to None it blocks indefinitely.
 
         Returns:
           True if an info event is ready to be read from the chip, False if the
index 37e8b62d0c63bcc10dfef4586810f660854a37c6..7b4598cb03b573425d3dcd4367d8d24c8cc0023d 100644 (file)
@@ -7,9 +7,6 @@ from typing import Optional, Union
 
 
 def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool:
-    if timeout is None:
-        timeout = 0.0
-
     if isinstance(timeout, timedelta):
         sec = timeout.total_seconds()
     else:
index a0f97b73903953887f01c433af83ac06d05e9636..090467ca13d0fe917774a87aeb36d80f36eee702 100644 (file)
@@ -178,7 +178,8 @@ class LineRequest:
         Args:
           timeout:
             Wait time limit expressed as either a datetime.timedelta object
-            or the number of seconds stored in a float.
+            or the number of seconds stored in a float. If set to 0, the
+            method returns immediately, if set to None it blocks indefinitely.
 
         Returns:
           True if events are ready to be read. False on timeout.