Skip to contentSkip to conversation

bindings: python: change the interpretation of None in event wait

PATCH In review Bartosz Golaszewski 3 participants 5 messages May 23, 2023 – May 24, 2023 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bindings: python: change the interpretation of None in event wait

From: Bartosz Golaszewski <[email protected]>

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 even 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.

---
 bindings/python/gpiod/chip.py         | 3 ++-
 bindings/python/gpiod/internal.py     | 3 ---
 bindings/python/gpiod/line_request.py | 3 ++-
 3 files changed, 4 insertions(+), 5 deletions(-)
bindings/python/gpiod/chip.py +2 -1
index 97ff340..52d0757 100644
@@ -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
bindings/python/gpiod/internal.py +0 -3
index 37e8b62..7b4598c 100644
@@ -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:
bindings/python/gpiod/line_request.py +2 -1
index a0f97b7..090467c 100644
@@ -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.
Signature · 1 line
2.39.2
#1 lore raw
Quoted 9 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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 even becomes available for reading.

Quoted 5 lines

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.

Cr*p, it was supposed to be Kent who suggested it and Nicolas who Reported it. I can change it when applying if the patch is fine.

Bart

Quoted 52 lines
---
 bindings/python/gpiod/chip.py         | 3 ++-
 bindings/python/gpiod/internal.py     | 3 ---
 bindings/python/gpiod/line_request.py | 3 ++-
 3 files changed, 4 insertions(+), 5 deletions(-)
bindings/python/gpiod/chip.py +2 -1
index 97ff340..52d0757 100644
@@ -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
bindings/python/gpiod/internal.py +0 -3
index 37e8b62..7b4598c 100644
@@ -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:
bindings/python/gpiod/line_request.py +2 -2
index a0f97b7..090467c 100644
@@ -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.
--

2.39.2

Reviewed-by
#2 lore raw
Quoted 14 lines · Bartosz Golaszewski
Quoted 13 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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 even 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.

Quoted 7 lines
Quoted 1 line

Cr*p, it was supposed to be Kent who suggested it and Nicolas who Reported it. I can change it when applying if the patch is fine.

Bart

Man, wish I could get away with that little sleep.

Anyway, that works for me.

#3 lore raw
In reply to Bartosz Golaszewski

Am Dienstag, 23. Mai 2023, 15:34:27 CEST schrieb Bartosz Golaszewski:

Quoted 6 lines

From: Bartosz Golaszewski <[email protected]>

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 even becomes available for

Small typo: 'an event becomes'

Regards,
Alexander

Quoted 58 lines

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.

---
 bindings/python/gpiod/chip.py         | 3 ++-
 bindings/python/gpiod/internal.py     | 3 ---
 bindings/python/gpiod/line_request.py | 3 ++-
 3 files changed, 4 insertions(+), 5 deletions(-)
bindings/python/gpiod/chip.py +0 -0
index 97ff340..52d0757 100644
@@ -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.

bindings/python/gpiod/chip.py +2 -0
+            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 37e8b62..7b4598c 100644

bindings/python/gpiod/internal.py +0 -0
@@ -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:

bindings/python/gpiod/internal.py +0 -2
-        timeout = 0.0
-
     if isinstance(timeout, timedelta):
         sec = timeout.total_seconds()
     else:
(quoted diff) +0 -0

b/bindings/python/gpiod/line_request.py index a0f97b7..090467c 100644

bindings/python/gpiod/line_request.py +2 -1
@@ -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.

Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/
author Applied
#4 lore raw
Quoted 10 lines · Alexander Stein

Am Dienstag, 23. Mai 2023, 15:34:27 CEST schrieb Bartosz Golaszewski:

Quoted 6 lines

From: Bartosz Golaszewski <[email protected]>

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 even becomes available for

Small typo: 'an event becomes'

Thanks, applied with that fixed.

Bart