Skip to content

Mark all extensions as free-threading safe #28819

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

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ jobs:
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
env:
CIBW_BUILD: "cp313-* cp313t-*"
# No free-threading wheels for NumPy; musllinux skipped for main builds also.
CIBW_SKIP: "cp313t-win_amd64 *-musllinux_aarch64"
CIBW_BUILD_FRONTEND:
"pip; args: --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple"
CIBW_FREE_THREADED_SUPPORT: true
Expand Down
22 changes: 22 additions & 0 deletions doc/users/next_whats_new/freethreading.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Preliminary support for free-threaded CPython 3.13
--------------------------------------------------

Matplotlib 3.10 has preliminary support for the free-threaded build of CPython 3.13. See
https://py-free-threading.github.io, `PEP 703 <https://peps.python.org/pep-0703/>`_ and
the `CPython 3.13 release notes
<https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython>`_ for more detail
about free-threaded Python.

Support for free-threaded Python does not mean that Matplotlib is wholly thread safe. We
expect that use of a Figure within a single thread will work, and though input data is
usually copied, modification of data objects used for a plot from another thread may
cause inconsistencies in cases where it is not. Use of any global state (such as the
``pyplot`` module) is highly discouraged and unlikely to work consistently. Also note
that most GUI toolkits expect to run on the main thread, so interactive usage may be
limited or unsupported from other threads.

If you are interested in free-threaded Python, for example because you have a
multiprocessing-based workflow that you are interested in running with Python threads, we
encourage testing and experimentation. If you run into problems that you suspect are
because of Matplotlib, please open an issue, checking first if the bug also occurs in the
“regular” non-free-threaded CPython 3.13 build.
2 changes: 1 addition & 1 deletion src/_backend_agg_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ PyRendererAgg_draw_gouraud_triangles(RendererAgg *self,
self->draw_gouraud_triangles(gc, points, colors, trans);
}

PYBIND11_MODULE(_backend_agg, m)
PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used())
{
py::class_<RendererAgg>(m, "RendererAgg", py::buffer_protocol())
.def(py::init<unsigned int, unsigned int, double>(),
Expand Down
2 changes: 1 addition & 1 deletion src/_c_internal_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ mpl_SetProcessDpiAwareness_max(void)
#endif
}

PYBIND11_MODULE(_c_internal_utils, m)
PYBIND11_MODULE(_c_internal_utils, m, py::mod_gil_not_used())
{
m.def(
"display_is_valid", &mpl_display_is_valid,
Expand Down
3 changes: 2 additions & 1 deletion src/_image_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ image_resample(py::array input_array,
}


PYBIND11_MODULE(_image, m) {
PYBIND11_MODULE(_image, m, py::mod_gil_not_used())
{
py::enum_<interpolation_e>(m, "_InterpolationType")
.value("NEAREST", NEAREST)
.value("BILINEAR", BILINEAR)
Expand Down
2 changes: 1 addition & 1 deletion src/_path_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ Py_is_sorted_and_has_non_nan(py::object obj)
return result;
}

PYBIND11_MODULE(_path, m)
PYBIND11_MODULE(_path, m, py::mod_gil_not_used())
{
m.def("point_in_path", &Py_point_in_path,
"x"_a, "y"_a, "radius"_a, "path"_a, "trans"_a);
Expand Down
3 changes: 2 additions & 1 deletion src/_qhull_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ delaunay(const CoordArray& x, const CoordArray& y, int verbose)
return delaunay_impl(npoints, x.data(), y.data(), verbose == 0);
}

PYBIND11_MODULE(_qhull, m) {
PYBIND11_MODULE(_qhull, m, py::mod_gil_not_used())
{
m.doc() = "Computing Delaunay triangulations.\n";

m.def("delaunay", &delaunay, "x"_a, "y"_a, "verbose"_a,
Expand Down
2 changes: 1 addition & 1 deletion src/_tkagg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ load_tkinter_funcs()
}
#endif // end not Windows

PYBIND11_MODULE(_tkagg, m)
PYBIND11_MODULE(_tkagg, m, py::mod_gil_not_used())
{
try {
load_tkinter_funcs();
Expand Down
2 changes: 1 addition & 1 deletion src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ PyFT2Font_fname(PyFT2Font *self)
}
}

PYBIND11_MODULE(ft2font, m)
PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
{
if (FT_Init_FreeType(&_ft2Library)) { // initialize library
throw std::runtime_error("Could not initialize the freetype2 library");
Expand Down
3 changes: 2 additions & 1 deletion src/tri/_tri_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

using namespace pybind11::literals;

PYBIND11_MODULE(_tri, m) {
PYBIND11_MODULE(_tri, m, py::mod_gil_not_used())
{
py::class_<Triangulation>(m, "Triangulation", py::is_final())
.def(py::init<const Triangulation::CoordinateArray&,
const Triangulation::CoordinateArray&,
Expand Down
Loading