Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should PyImport_AppendInittab() be called before Py_Initialize()?

Tags:

c++

python

According to the documentation, PyImport_AppendInittab "should be called before Py_Initialize()."

There is no explanation of why this is the case, and ignoring this advice yields a working application. So, since this is working, under what circumstances will it not work?

like image 406
Daniel F Avatar asked Sep 04 '12 14:09

Daniel F


1 Answers

Because the documentation says so; and violating the API might yield a working application today but not tomorrow.

A couple of issues you might encounter:

  • sys.builtin_module_names is initialized within Py_Initialize, so it won't contain your module
  • PyImport_AppendInittab does not take any locks, so if you call it after Py_Initialize in a multithreaded application you could get memory corruption
like image 102
ecatmur Avatar answered Oct 29 '22 16:10

ecatmur