Skip to content

Commit

Permalink
make test runnable on GIL-enabled build
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Sep 24, 2024
1 parent 258804d commit 27eaf02
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
12 changes: 6 additions & 6 deletions pytests/src/pyclasses.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{thread, time};

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

#[pymethods]
Expand All @@ -59,12 +58,13 @@ impl PyClassThreadIter {
Default::default()
}

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

Expand Down
5 changes: 0 additions & 5 deletions pytests/tests/test_pyclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import pytest
from pyo3_pytests import pyclasses

FREETHREADED_BUILD = bool(sysconfig.get_config_var("Py_GIL_DISABLED"))


def test_empty_class_init(benchmark):
benchmark(pyclasses.EmptyClass)
Expand Down Expand Up @@ -57,9 +55,6 @@ def test_iter():
assert excinfo.value.value == "Ended"


@pytest.mark.skipif(
not FREETHREADED_BUILD, reason="The GIL enforces runtime borrow checking"
)
def test_parallel_iter():
i = pyclasses.PyClassThreadIter()

Expand Down

0 comments on commit 27eaf02

Please sign in to comment.