From 3004d20bf9261f966ece53b693405978ae2f29ba Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Thu, 1 Feb 2024 09:07:15 +0100 Subject: [PATCH] WIP Don't overwrite _COb in PInit --- layer1/P.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/layer1/P.cpp b/layer1/P.cpp index 33bc9b50c..f858addc5 100644 --- a/layer1/P.cpp +++ b/layer1/P.cpp @@ -1914,8 +1914,12 @@ void PInit(PyMOLGlobals * G, int global_instance) if(global_instance) { assert(SingletonPyMOLGlobals); /* implies global singleton pymol, so set up the global handle */ - PyObject_SetAttrString(P_cmd, "_COb", - PyCapsule_New(&SingletonPyMOLGlobals, nullptr, nullptr)); + + auto cob = PyObject_GetAttrString(P_cmd, "_COb"); + if (!cob || cob == Py_None) { + PyObject_SetAttrString(P_cmd, "_COb", + PyCapsule_New(&SingletonPyMOLGlobals, nullptr, nullptr)); + } /* cmd module is itself the api for the global PyMOL instance */ G->P_inst->cmd = P_cmd;