8000 gh-115490: Make the interpreter.channels and interpreter.queues Modules Handle Reloading Properly by ericsnowcurrently · Pull Request #115493 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115490: Make the interpreter.channels and interpreter.queues Modules Handle Reloading Properly #115493

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
Prev Previous commit
Next Next commit
Fix the queues module.
  • Loading branch information
ericsnowcurrently committed Feb 14, 2024
commit 55866852f19cd01a915fbf9ab571826ada515ec3
16 changes: 9 additions & 7 deletions Modules/_xxinterpqueuesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ static int
clear_module_state(module_state *state)
{
/* external types */
if (state->queue_type != NULL) {
(void)_PyCrossInterpreterData_UnregisterClass(state->queue_type);
}
Py_CLEAR(state->queue_type);

/* QueueError */
Expand Down Expand Up @@ -1060,15 +1063,18 @@ set_external_queue_type(PyObject *module, PyTypeObject *queue_type)
{
module_state *state = get_module_state(module);

// Clear the old value if the .py module was reloaded.
if (state->queue_type != NULL) {
PyErr_SetString(PyExc_TypeError, "already registered");
return -1;
(void)_PyCrossInterpreterData_UnregisterClass(
state->queue_type);
Py_CLEAR(state->queue_type);
}
state->queue_type = (PyTypeObject *)Py_NewRef(queue_type);

// Add and register the new type.
if (ensure_xid_class(queue_type, _queueobj_shared) < 0) {
return -1;
}
state->queue_type = (PyTypeObject *)Py_NewRef(queue_type);

return 0;
}
Expand Down Expand Up @@ -1652,10 +1658,6 @@ module_clear(PyObject *mod)
{
module_state *state = get_module_state(mod);

if (state->queue_type != NULL) {
(void)_PyCrossInterpreterData_UnregisterClass(state->queue_type);
}

// Now we clear the module state.
clear_module_state(state);
return 0;
Expand Down
0