Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@crusaderky

Description

@crusaderky
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug39 - free-threadingPRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.