Skip to content

Instantly share code, notes, and snippets.

@nascheme
Created June 29, 2024 21:59
Show Gist options
  • Save nascheme/e807f03fd15312bbae52595f21ad0957 to your computer and use it in GitHub Desktop.
Save nascheme/e807f03fd15312bbae52595f21ad0957 to your computer and use it in GitHub Desktop.
diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c
index 21fc0059d..eb2e054fe 100644
--- a/src/plugins/python/weechat-python.c
+++ b/src/plugins/python/weechat-python.c
@@ -901,6 +901,26 @@ weechat_python_load_cb (void *data, const char *filename)
weechat_python_load (filename, NULL);
}
+static void
+clear_weechat_module(void)
+{
+ PyObject *n = PyUnicode_FromString("weechat");
+ if (!n) {
+ return;
+ }
+ PyObject *m = PyImport_GetModule(n);
+ Py_DECREF(n);
+ if (!m) {
+ return;
+ }
+ PyObject *d = PyModule_GetDict(m);
+ if (!d) {
+ return;
+ }
+ PyDict_Clear(d);
+}
+
+
/*
* Unloads a python script.
*/
@@ -941,6 +961,7 @@ weechat_python_unload (struct t_plugin_script *script)
if (interpreter)
{
PyThreadState_Swap (interpreter);
+ clear_weechat_module();
Py_EndInterpreter (interpreter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment