aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-05-23 15:29:29 +0200
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-05-24 11:12:49 +0200
commita0b8bcee3f46b42b16d9073252934694a971af96 (patch)
tree84155144d6bbd015314425c4ac78a4db9b0f6ed5
parent8f3cd2b6b4c4038a8f87cd89d78edb0ec2c9dff6 (diff)
downloadlibgpiod-a0b8bcee3f46b42b16d9073252934694a971af96.tar.gz
bindings: python: change the interpretation of None in event wait
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>
-rw-r--r--bindings/python/gpiod/chip.py3
-rw-r--r--bindings/python/gpiod/internal.py3
-rw-r--r--bindings/python/gpiod/line_request.py3
3 files changed, 4 insertions, 5 deletions
diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py
index 97ff340c..52d0757e 100644
--- a/bindings/python/gpiod/chip.py
+++ b/bindings/python/gpiod/chip.py
@@ -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
diff --git a/bindings/python/gpiod/internal.py b/bindings/python/gpiod/internal.py
index 37e8b62d..7b4598cb 100644
--- a/bindings/python/gpiod/internal.py
+++ b/bindings/python/gpiod/internal.py
@@ -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:
diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py
index a0f97b73..090467ca 100644
--- a/bindings/python/gpiod/line_request.py
+++ b/bindings/python/gpiod/line_request.py
@@ -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.