Skip to content

Commit

Permalink
make test use an atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Sep 24, 2024
1 parent 1ea1034 commit 258804d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pytests/src/pyclasses.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{thread, time};

use pyo3::exceptions::{PyStopIteration, PyValueError};
Expand Down Expand Up @@ -48,7 +49,7 @@ impl PyClassIter {
#[pyclass]
#[derive(Default)]
struct PyClassThreadIter {
count: usize,
count: AtomicUsize,
}

#[pymethods]
Expand All @@ -59,12 +60,11 @@ impl PyClassThreadIter {
}

fn __next__(&mut self) -> usize {
let should_wait = self.count == 0;
self.count += 1;
if should_wait {
let current_count = self.count.fetch_add(1, Ordering::SeqCst);
if current_count == 0 {
thread::sleep(time::Duration::from_millis(100));
}
self.count
current_count
}
}

Expand Down

0 comments on commit 258804d

Please sign in to comment.