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

Commit d01249c

Browse filesBrowse files
authored
Merge pull request #26913 from ngoldbaum/declare-nogil
MAINT: declare that NumPy's C extensions support running without the GIL
2 parents 7896d73 + f79560c commit d01249c
Copy full SHA for d01249c

12 files changed

+58
-0
lines changed

‎numpy/_core/src/_simd/_simd.c

Copy file name to clipboardExpand all lines: numpy/_core/src/_simd/_simd.c
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ PyMODINIT_FUNC PyInit__simd(void)
9292
NPY__CPU_DISPATCH_CALL(NPY_CPU_HAVE, ATTACH_MODULE, MAKE_MSVC_HAPPY)
9393
NPY__CPU_DISPATCH_BASELINE_CALL(ATTACH_BASELINE_MODULE, MAKE_MSVC_HAPPY)
9494
#endif
95+
96+
#if Py_GIL_DISABLED
97+
// signal this module supports running with the GIL disabled
98+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
99+
#endif
100+
95101
return m;
96102
err:
97103
Py_DECREF(m);

‎numpy/_core/src/multiarray/_multiarray_tests.c.src

Copy file name to clipboardExpand all lines: numpy/_core/src/multiarray/_multiarray_tests.c.src
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,12 @@ PyMODINIT_FUNC PyInit__multiarray_tests(void)
24392439
PyErr_SetString(PyExc_RuntimeError,
24402440
"cannot load _multiarray_tests module.");
24412441
}
2442+
2443+
#if Py_GIL_DISABLED
2444+
// signal this module supports running with the GIL disabled
2445+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
2446+
#endif
2447+
24422448
return m;
24432449
}
24442450

‎numpy/_core/src/multiarray/multiarraymodule.c

Copy file name to clipboardExpand all lines: numpy/_core/src/multiarray/multiarraymodule.c
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,6 +5137,11 @@ PyMODINIT_FUNC PyInit__multiarray_umath(void) {
51375137
goto err;
51385138
}
51395139

5140+
#if Py_GIL_DISABLED
5141+
// signal this module supports running with the GIL disabled
5142+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
5143+
#endif
5144+
51405145
return m;
51415146

51425147
err:

‎numpy/_core/src/umath/_operand_flag_tests.c

Copy file name to clipboardExpand all lines: numpy/_core/src/umath/_operand_flag_tests.c
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ PyMODINIT_FUNC PyInit__operand_flag_tests(void)
7777
((PyUFuncObject*)ufunc)->iter_flags = NPY_ITER_REDUCE_OK;
7878
PyModule_AddObject(m, "inplace_add", (PyObject*)ufunc);
7979

80+
#if Py_GIL_DISABLED
81+
// signal this module supports running with the GIL disabled
82+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
83+
#endif
84+
8085
return m;
8186

8287
fail:

‎numpy/_core/src/umath/_rational_tests.c

Copy file name to clipboardExpand all lines: numpy/_core/src/umath/_rational_tests.c
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,11 @@ PyMODINIT_FUNC PyInit__rational_tests(void) {
13551355
GCD_LCM_UFUNC(gcd,NPY_INT64,"greatest common denominator of two integers");
13561356
GCD_LCM_UFUNC(lcm,NPY_INT64,"least common multiple of two integers");
13571357

1358+
#if Py_GIL_DISABLED
1359+
// signal this module supports running with the GIL disabled
1360+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
1361+
#endif
1362+
13581363
return m;
13591364

13601365
fail:

‎numpy/_core/src/umath/_struct_ufunc_tests.c

Copy file name to clipboardExpand all lines: numpy/_core/src/umath/_struct_ufunc_tests.c
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,11 @@ PyMODINIT_FUNC PyInit__struct_ufunc_tests(void)
156156

157157
PyDict_SetItemString(d, "add_triplet", add_triplet);
158158
Py_DECREF(add_triplet);
159+
160+
#if Py_GIL_DISABLED
161+
// signal this module supports running with the GIL disabled
162+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
163+
#endif
164+
159165
return m;
160166
}

‎numpy/_core/src/umath/_umath_tests.c.src

Copy file name to clipboardExpand all lines: numpy/_core/src/umath/_umath_tests.c.src
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,5 +829,11 @@ PyMODINIT_FUNC PyInit__umath_tests(void) {
829829
"cannot load _umath_tests module.");
830830
return NULL;
831831
}
832+
833+
#if Py_GIL_DISABLED
834+
// signal this module supports running with the GIL disabled
835+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
836+
#endif
837+
832838
return m;
833839
}

‎numpy/f2py/tests/test_abstract_interface.py

Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_abstract_interface.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from numpy.testing import IS_WASM
77

88

9+
@pytest.mark.filterwarnings(r"ignore:.*The global interpreter lock \(GIL\) "
10+
r"has been enabled.*:RuntimeWarning")
911
@pytest.mark.skipif(IS_WASM, reason="Cannot start subprocess")
1012
@pytest.mark.slow
1113
class TestAbstractInterface(util.F2PyTest):

‎numpy/f2py/tests/test_callback.py

Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_callback.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from . import util
1212

1313

14+
@pytest.mark.filterwarnings(r"ignore:.*The global interpreter lock \(GIL\) "
15+
r"has been enabled.*:RuntimeWarning")
1416
class TestF77Callback(util.F2PyTest):
1517
sources = [util.getpath("tests", "src", "callback", "foo.f")]
1618

‎numpy/fft/_pocketfft_umath.cpp

Copy file name to clipboardExpand all lines: numpy/fft/_pocketfft_umath.cpp
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,5 +419,10 @@ PyMODINIT_FUNC PyInit__pocketfft_umath(void)
419419
return NULL;
420420
}
421421

422+
#if Py_GIL_DISABLED
423+
// signal this module supports running with the GIL disabled
424+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
425+
#endif
426+
422427
return m;
423428
}

‎numpy/linalg/lapack_litemodule.c

Copy file name to clipboardExpand all lines: numpy/linalg/lapack_litemodule.c
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,10 @@ PyMODINIT_FUNC PyInit_lapack_lite(void)
409409
PyDict_SetItemString(d, "_ilp64", Py_False);
410410
#endif
411411

412+
#if Py_GIL_DISABLED
413+
// signal this module supports running with the GIL disabled
414+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
415+
#endif
416+
412417
return m;
413418
}

‎numpy/linalg/umath_linalg.cpp

Copy file name to clipboardExpand all lines: numpy/linalg/umath_linalg.cpp
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,5 +4699,10 @@ PyMODINIT_FUNC PyInit__umath_linalg(void)
46994699
PyDict_SetItemString(d, "_ilp64", Py_False);
47004700
#endif
47014701

4702+
#if Py_GIL_DISABLED
4703+
// signal this module supports running with the GIL disabled
4704+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
4705+
#endif
4706+
47024707
return m;
47034708
}

0 commit comments

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