Skip to content

Commit 6e9be45

Browse files
committed
Add support for Python subinterpreters
Note, at this time, NumPy does not support subinterpreters, and so we do not either.
1 parent c2912cb commit 6e9be45

6 files changed

Lines changed: 49 additions & 10 deletions

File tree

src/_backend_agg_wrapper.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <pybind11/pybind11.h>
22
#include <pybind11/numpy.h>
33
#include <pybind11/stl.h>
4+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
5+
#include <pybind11/subinterpreter.h>
6+
#endif
7+
48
#include "mplutils.h"
59
#include "py_converters.h"
610
#include "_backend_agg.h"
@@ -185,7 +189,11 @@ PyRendererAgg_draw_gouraud_triangles(RendererAgg *self,
185189
self->draw_gouraud_triangles(gc, points, colors, trans);
186190
}
187191

188-
PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used())
192+
PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used()
193+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
194+
,py::multiple_interpreters::per_interpreter_gil()
195+
#endif
196+
)
189197
{
190198
py::classh<RendererAgg>(m, "RendererAgg", py::buffer_protocol())
191199
.def(py::init<unsigned int, unsigned int, double>(),

src/_image_wrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include <pybind11/pybind11.h>
22
#include <pybind11/native_enum.h>
33
#include <pybind11/numpy.h>
4+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
5+
#include <pybind11/subinterpreter.h>
6+
#endif
47

58
#include <algorithm>
69

@@ -288,7 +291,11 @@ calculate_rms_and_diff(py::array_t<unsigned char> expected_image,
288291
}
289292

290293

291-
PYBIND11_MODULE(_image, m, py::mod_gil_not_used())
294+
PYBIND11_MODULE(_image, m, py::mod_gil_not_used()
295+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
296+
,py::multiple_interpreters::per_interpreter_gil()
297+
#endif
298+
)
292299
{
293300
py::native_enum<interpolation_e>(m, "_InterpolationType", "enum.Enum")
294301
.value("NEAREST", NEAREST)

src/_path_wrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include <pybind11/pybind11.h>
22
#include <pybind11/stl.h>
3+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
4+
#include <pybind11/subinterpreter.h>
5+
#endif
36

47
#include <array>
58
#include <limits>
@@ -303,7 +306,11 @@ Py_is_sorted_and_has_non_nan(py::object obj)
303306
return result;
304307
}
305308

306-
PYBIND11_MODULE(_path, m, py::mod_gil_not_used())
309+
PYBIND11_MODULE(_path, m, py::mod_gil_not_used()
310+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
311+
,py::multiple_interpreters::per_interpreter_gil()
312+
#endif
313+
)
307314
{
308315
m.def("point_in_path", &Py_point_in_path,
309316
"x"_a, "y"_a, "radius"_a, "path"_a, "trans"_a);

src/_qhull_wrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
#include <pybind11/pybind11.h>
99
#include <pybind11/numpy.h>
10+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
11+
#include <pybind11/subinterpreter.h>
12+
#endif
1013

1114
#ifdef _MSC_VER
1215
/* The Qhull header does not declare this as extern "C", but only MSVC seems to
@@ -284,7 +287,11 @@ delaunay(const CoordArray& x, const CoordArray& y, int verbose)
284287
return delaunay_impl(npoints, x.data(), y.data(), verbose == 0);
285288
}
286289

287-
PYBIND11_MODULE(_qhull, m, py::mod_gil_not_used())
290+
PYBIND11_MODULE(_qhull, m, py::mod_gil_not_used()
291+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
292+
,py::multiple_interpreters::per_interpreter_gil()
293+
#endif
294+
)
288295
{
289296
m.doc() = "Computing Delaunay triangulations.\n";
290297

src/ft2font_wrapper.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include <pybind11/native_enum.h>
44
#include <pybind11/numpy.h>
55
#include <pybind11/stl.h>
6+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
7+
#include <pybind11/subinterpreter.h>
8+
#endif
69

710
#include "ft2font.h"
811

@@ -1393,11 +1396,11 @@ PyFT2Font_layout(PyFT2Font *self, std::u32string text, LoadFlags flags,
13931396
return items;
13941397
}
13951398

1396-
/**********************************************************************
1397-
* Deprecations
1398-
* */
1399-
1400-
PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1399+
PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used()
1400+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
1401+
,py::multiple_interpreters::per_interpreter_gil()
1402+
#endif
1403+
)
14011404
{
14021405
FT_Library ft2Library = nullptr;
14031406

src/tri/_tri_wrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
#include "_tri.h"
2+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
3+
#include <pybind11/subinterpreter.h>
4+
#endif
25

36
using namespace pybind11::literals;
47

5-
PYBIND11_MODULE(_tri, m, py::mod_gil_not_used())
8+
PYBIND11_MODULE(_tri, m, py::mod_gil_not_used()
9+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
10+
,py::multiple_interpreters::per_interpreter_gil()
11+
#endif
12+
)
613
{
714
py::classh<Triangulation>(m, "Triangulation", py::is_final())
815
.def(py::init<const Triangulation::CoordinateArray&,

0 commit comments

Comments
 (0)