PyO3 freelist is unsound with GIL disabled

This commit is contained in:
Giovanni Barillari 2025-02-10 22:46:08 +01:00
parent 21616d6db1
commit cde2400fa3
No known key found for this signature in database
2 changed files with 14 additions and 4 deletions

View file

@ -284,7 +284,7 @@ impl CallbackScheduler {
}
}
#[pyclass(frozen, freelist = 1024, module = "granian._granian")]
#[pyclass(frozen, module = "granian._granian")]
pub(crate) struct CallbackSchedulerState {
sched: Py<CallbackScheduler>,
coro: PyObject,
@ -353,7 +353,12 @@ impl CallbackSchedulerState {
}
}
#[pyclass(frozen, module = "granian._granian")]
// see https://github.com/PyO3/pyo3/issues/4894 - freelist is currently unsound with GIL disabled
#[cfg_attr(
not(Py_GIL_DISABLED),
pyclass(frozen, freelist = 64, module = "granian._granian")
)]
#[cfg_attr(Py_GIL_DISABLED, pyclass(frozen, module = "granian._granian"))]
pub(crate) struct PyEmptyAwaitable;
#[pymethods]

View file

@ -21,6 +21,7 @@ async def _server(interface, port, threading_mode, tls=False, task_impl='asyncio
kwargs = {
'interface': interface,
'port': port,
'loop': 'asyncio',
'blocking_threads': 1,
'threading_mode': threading_mode,
'task_impl': task_impl,
@ -53,7 +54,9 @@ async def _server(interface, port, threading_mode, tls=False, task_impl='asyncio
break
proc.terminate()
proc.join()
proc.join(timeout=2)
if proc.is_alive():
proc.kill()
spawn_failures += 1
if not succeeded:
@ -63,7 +66,9 @@ async def _server(interface, port, threading_mode, tls=False, task_impl='asyncio
yield port
finally:
proc.terminate()
proc.join()
proc.join(timeout=2)
if proc.is_alive():
proc.kill()
@pytest.fixture(scope='function')