Skip to content

Commit bc06e57

Browse files
committed
Demonstrate indefinite iteration on samples.
1 parent effbfc3 commit bc06e57

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

examples/tl-samples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
columns = ["imu.accel*"] # Wildcard
99
# columns = ["imu.accel.x", "imu.accel.y", "imu.accel.z"] # Specific columns
1010

11-
for sample in dev._samples(5, columns):
11+
for sample in dev._samples(n=None, columns=columns):
1212
print(sample)

rust/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ impl PyIter {
2121
fn __next__(mut slf: PyRefMut<'_, Self>) -> PyResult<Option<Py<PyAny>>> {
2222
let dict = PyDict::new(slf.py());
2323

24+
// Check if we have a finite count and if it's reached zero
2425
if let Some(ctr) = slf.n {
2526
if ctr == 0 {
2627
// TODO: drop port
@@ -29,6 +30,7 @@ impl PyIter {
2930
slf.n = Some(ctr - 1);
3031
}
3132
}
33+
// If n is None, we continue indefinitely
3234

3335
while dict.is_empty() {
3436
// Check for keyboard interrupt
@@ -112,7 +114,7 @@ impl PyDevice {
112114
}
113115
}
114116

115-
#[pyo3(signature = (n=1, stream=None, columns=None))]
117+
#[pyo3(signature = (n=None, stream=None, columns=None))]
116118
fn _samples<'py>(
117119
&self,
118120
_py: Python<'py>,

0 commit comments

Comments
 (0)