On 16 March 2015 Petr Viktorin wrote: > If PyModuleCreate is not defined, PyModuleExec is expected to operate > on any Python object for which attributes can be added by PyObject_GetAttr* > and retrieved by PyObject_SetAttr*.
I assume it is the other way around (add with Set and retrieve with Get), rather than a description of the required form of magic. > PyObject *PyModule_AddCapsule( > PyObject *module, > const char *module_name, > const char *attribute_name, > void *pointer, > PyCapsule_Destructor destructor) What happens if module_name doesn't match the module's __name__? Does it become a hidden attribute? A dotted attribute? Is the result undefined? Later, there is > void *PyModule_GetCapsulePointer( > PyObject *module, > const char *module_name, > const char *attribute_name) with the same apparently redundant arguments, but not a PyModule_SetCapsulePointer. Are capsule pointers read-only, or can they be replaced with another call to PyModule_AddCapsule, or by a simple PyObject_SetAttr? > Subinterpreters and Interpreter Reloading ... > No user-defined functions, methods, or instances may leak to different > interpreters. By "user-defined" do you mean "defined in python, as opposed to in the extension itself"? If so, what is the recommendation for modules that do want to support, say, callbacks? A dual-layer mapping that uses the interpreter as the first key? Naming it _module and only using it indirectly through module.py, which is not shared across interpreters? Not using this API at all? > To achieve this, all module-level state should be kept in either the module > dict, or in the module object. I don't see how that is related to leakage. > A simple rule of thumb is: Do not define any static data, except > built-in types > with no mutable or user-settable class attributes. What about singleton instances? Should they be per-interpreter? What about constants, such as PI? Where should configuration variables (e.g., MAX_SEARCH_DEPTH) be kept? What happens if this no-leakage rule is violated? Does the module not load, or does it just maybe lead to a crash down the road? -jJ -- If there are still threading problems with my replies, please email me with details, so that I can try to resolve them. -jJ _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com