PyDateTime_IMPORT macro does not initialize PyDateTimeAPI variable

I use the Python C API on Windows using Visual Studio 2008. When I try to use a macro PyDate_Checkand other related macros, they cause an access violation because the static variable PyDateTimeAPI is zero. This variable is initialized using a macro PyDateTime_IMPORTthat needs to be called before using any time macros. I do this when creating a new Python sub-interpreter in a separate thread.

A couple of questions :
- Why the function PyCObject_Importin the macro PyDateTime_IMPORTreturns null. I understand that the null return value is because the module cannot be found. But how can the datetime module not be found? Maybe due to incorrect sys.path in the sub-interpreter? “Also, I call the macro PyDateTime_IMPORTin the right place, should it be right after the sub-interpreter is initialized, or when the Python interpreter is initialized?”

PyDateTime_IMPORT:

#define PyDateTime_IMPORT \
    PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import("datetime", \
                                                        "datetime_CAPI")`
+3
source share
2 answers

, g++ Python 3.2. , PyDateTimeAPI , , , .

+2

PyCObject 2.7 3.x. PyCObject_Import()

PyCapsule_Import()
0

Source: https://habr.com/ru/post/1720912/


All Articles