Skip to content

BUG: noGIL: segfault in custom dtype creation C API #29127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
crusaderky opened this issue Jun 4, 2025 · 2 comments
Open

BUG: noGIL: segfault in custom dtype creation C API #29127

crusaderky opened this issue Jun 4, 2025 · 2 comments
Labels
00 - Bug 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)

Comments

@crusaderky
Copy link
Contributor

crusaderky commented Jun 4, 2025

Describe the issue:

A test that invokes C APIs segfaults when run from multiple threads in parallel in python 3.13t:

def test_custom_structured_dtype(self):
class mytype:
pass
blueprint = np.dtype([("field", object)])
dt = create_custom_field_dtype(blueprint, mytype, 0)

The test invokes a test-specific C function, which however upon cursory inspection doesn't seem to have anything untowards in it. The C function in turn calls: Py_SET_TYPE, PyArray_RegisterDataType, PyArray_DescrFromType:

create_custom_field_dtype(PyObject *NPY_UNUSED(mod), PyObject *args)

Reproduce the code example:

  1. deploy numpy through https://github.com/rgommers/pixi-dev-scipystack/
  2. apply patch (see DEV: stop monkeypatching and use of autouse=True fixtures by default in test suite #29090):
--- a/numpy/conftest.py
+++ b/numpy/conftest.py
@@ -147,9 +147,10 @@ def check_fpu_mode(request):
 def add_np(doctest_namespace):
     doctest_namespace['np'] = numpy
 
+
 @pytest.fixture(autouse=True)
-def env_setup(monkeypatch):
-    monkeypatch.setenv('PYTHONHASHSEED', '0')
+def env_setup():
+    os.environ['PYTHONHASHSEED'] = '0'
  1. pixi run test-nogil -- -k test_custom_structured_dtype --parallel-threads=32

Python and NumPy Versions:

python 3.13t
numpy git tip 2025-06-04

Runtime Environment:

32-core x86_64 Linux host

@ngoldbaum
Copy link
Member

We had similar reports from Jax about thread safety issues around adding legacy DTypes - not terribly surprising there are more problems.

@ngoldbaum ngoldbaum added the 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) label Jun 4, 2025
@seberg
Copy link
Member

seberg commented Jun 4, 2025

Not sure I am convinced that this needs fixing in more then tests it is not sane use here... but maybe it's trivial enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)
Projects
None yet
Development

No branches or pull requests

3 participants