Skip to content

Commit 992072b

Browse files
committed
Register PyBuffer in subinterpreters
PyBuffer was only registered in the main interpreter, causing ImportError when using subinterpreters (Python 3.12+). Add PyBuffer_register_with_module() calls in: - py_subinterp_pool.c: for shared-GIL subinterpreter pool - py_subinterp_thread.c: for OWN_GIL subinterpreter threads
1 parent f1d8b81 commit 992072b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

c_src/py_subinterp_pool.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "py_subinterp_pool.h"
2828
#include "py_reactor_buffer.h"
29+
#include "py_buffer.h"
2930
#include <string.h>
3031

3132
#ifdef HAVE_SUBINTERPRETERS
@@ -170,6 +171,12 @@ int subinterp_pool_init(int size) {
170171
/* Non-fatal - ReactorBuffer just won't be available */
171172
}
172173

174+
/* Register PyBuffer with erlang module in this subinterpreter */
175+
if (PyBuffer_register_with_module() < 0) {
176+
PyErr_Clear();
177+
/* Non-fatal - PyBuffer just won't be available */
178+
}
179+
173180
/* Import erlang module into globals */
174181
PyObject *erlang_module = PyImport_ImportModule("erlang");
175182
if (erlang_module != NULL) {

c_src/py_subinterp_thread.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "py_subinterp_thread.h"
2727
#include "py_nif.h"
28+
#include "py_buffer.h"
2829
#include <string.h>
2930
#include <unistd.h>
3031
#include <fcntl.h>
@@ -315,6 +316,12 @@ static void *worker_thread_main(void *arg) {
315316
fprintf(stderr, "worker %d: failed to create erlang module\n", w->worker_id);
316317
PyErr_Clear();
317318
/* Continue without erlang module - callbacks won't work */
319+
} else {
320+
/* Register PyBuffer with erlang module in this subinterpreter */
321+
if (PyBuffer_register_with_module() < 0) {
322+
PyErr_Clear();
323+
/* Non-fatal - PyBuffer just won't be available */
324+
}
318325
}
319326

320327
/* Release the subinterpreter's GIL (we'll acquire it per-request) */

0 commit comments

Comments
 (0)