4

I need to import one of the core modules (datetime) inside my C extension module since I want to return a datetime.date from some functions of my module.

It appears that Python C extension modules have no complement for the PyMODINIT_FUNC upon destruction.

Question: What can I do short of importing the required module time and time again in every call inside my C extension module and then dereferencing it at the end of the call(s) again?

Rationale: Basically I fear that this (importing it over and over again) creates an unnecessary overhead, because from my understanding of the documentation dereferencing it means that the garbage collector can come around and collect it, so next time PyImport_ImportModule would have to be called again.

Somewhat related questions:

Community
  • 1
  • 1
0xC0000022L
  • 20,597
  • 9
  • 86
  • 152

0 Answers0