Skip to content

Commit 9489b93

Browse files
authored
Merge pull request matplotlib#28819 from QuLogic/freethread
Mark all extensions as free-threading safe
2 parents fd452d2 + 0cf28c2 commit 9489b93

File tree

10 files changed

+33
-10
lines changed

10 files changed

+33
-10
lines changed

.github/workflows/cibuildwheel.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ jobs:
148148
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
149149
env:
150150
CIBW_BUILD: "cp313-* cp313t-*"
151-
# No free-threading wheels for NumPy; musllinux skipped for main builds also.
152-
CIBW_SKIP: "cp313t-win_amd64 *-musllinux_aarch64"
153151
CIBW_BUILD_FRONTEND:
154152
"pip; args: --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple"
155153
CIBW_FREE_THREADED_SUPPORT: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Preliminary support for free-threaded CPython 3.13
2+
--------------------------------------------------
3+
4+
Matplotlib 3.10 has preliminary support for the free-threaded build of CPython 3.13. See
5+
https://py-free-threading.github.io, `PEP 703 <https://peps.python.org/pep-0703/>`_ and
6+
the `CPython 3.13 release notes
7+
<https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython>`_ for more detail
8+
about free-threaded Python.
9+
10+
Support for free-threaded Python does not mean that Matplotlib is wholly thread safe. We
11+
expect that use of a Figure within a single thread will work, and though input data is
12+
usually copied, modification of data objects used for a plot from another thread may
13+
cause inconsistencies in cases where it is not. Use of any global state (such as the
14+
``pyplot`` module) is highly discouraged and unlikely to work consistently. Also note
15+
that most GUI toolkits expect to run on the main thread, so interactive usage may be
16+
limited or unsupported from other threads.
17+
18+
If you are interested in free-threaded Python, for example because you have a
19+
multiprocessing-based workflow that you are interested in running with Python threads, we
20+
encourage testing and experimentation. If you run into problems that you suspect are
21+
because of Matplotlib, please open an issue, checking first if the bug also occurs in the
22+
“regular” non-free-threaded CPython 3.13 build.

src/_backend_agg_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ PyRendererAgg_draw_gouraud_triangles(RendererAgg *self,
185185
self->draw_gouraud_triangles(gc, points, colors, trans);
186186
}
187187

188-
PYBIND11_MODULE(_backend_agg, m)
188+
PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used())
189189
{
190190
py::class_<RendererAgg>(m, "RendererAgg", py::buffer_protocol())
191191
.def(py::init<unsigned int, unsigned int, double>(),

src/_c_internal_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ mpl_SetProcessDpiAwareness_max(void)
196196
#endif
197197
}
198198

199-
PYBIND11_MODULE(_c_internal_utils, m)
199+
PYBIND11_MODULE(_c_internal_utils, m, py::mod_gil_not_used())
200200
{
201201
m.def(
202202
"display_is_valid", &mpl_display_is_valid,

src/_image_wrapper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ image_resample(py::array input_array,
200200
}
201201

202202

203-
PYBIND11_MODULE(_image, m) {
203+
PYBIND11_MODULE(_image, m, py::mod_gil_not_used())
204+
{
204205
py::enum_<interpolation_e>(m, "_InterpolationType")
205206
.value("NEAREST", NEAREST)
206207
.value("BILINEAR", BILINEAR)

src/_path_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ Py_is_sorted_and_has_non_nan(py::object obj)
368368
return result;
369369
}
370370

371-
PYBIND11_MODULE(_path, m)
371+
PYBIND11_MODULE(_path, m, py::mod_gil_not_used())
372372
{
373373
m.def("point_in_path", &Py_point_in_path,
374374
"x"_a, "y"_a, "radius"_a, "path"_a, "trans"_a);

src/_qhull_wrapper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ delaunay(const CoordArray& x, const CoordArray& y, int verbose)
276276
return delaunay_impl(npoints, x.data(), y.data(), verbose == 0);
277277
}
278278

279-
PYBIND11_MODULE(_qhull, m) {
279+
PYBIND11_MODULE(_qhull, m, py::mod_gil_not_used())
280+
{
280281
m.doc() = "Computing Delaunay triangulations.\n";
281282

282283
m.def("delaunay", &delaunay, "x"_a, "y"_a, "verbose"_a,

src/_tkagg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ load_tkinter_funcs()
333333
}
334334
#endif // end not Windows
335335

336-
PYBIND11_MODULE(_tkagg, m)
336+
PYBIND11_MODULE(_tkagg, m, py::mod_gil_not_used())
337337
{
338338
try {
339339
load_tkinter_funcs();

src/ft2font_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ PyFT2Font_fname(PyFT2Font *self)
952952
}
953953
}
954954

955-
PYBIND11_MODULE(ft2font, m)
955+
PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
956956
{
957957
if (FT_Init_FreeType(&_ft2Library)) { // initialize library
958958
throw std::runtime_error("Could not initialize the freetype2 library");

src/tri/_tri_wrapper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
using namespace pybind11::literals;
44

5-
PYBIND11_MODULE(_tri, m) {
5+
PYBIND11_MODULE(_tri, m, py::mod_gil_not_used())
6+
{
67
py::class_<Triangulation>(m, "Triangulation", py::is_final())
78
.def(py::init<const Triangulation::CoordinateArray&,
89
const Triangulation::CoordinateArray&,

0 commit comments

Comments
 (0)