Hello,<br><br>I work with a 3rd party tool that provides a C API for customization.<br><br>I created Python bindings for this C API so my customizations are nothing more than this example wrapper code almost verbatim:<br>    <a href="http://docs.python.org/extending/embedding.html#pure-embedding">http://docs.python.org/extending/embedding.html#pure-embedding</a><br>
I have many .c files just like that only differing by the module and function that they load and execute.<br><br>This has been working fine for a long time.  Now, as we add more and more customizations that get triggered at various events we have come to a problem.<br>
If some of the Python customization code gets triggered from inside another Python customization I get a segfault.<br>I thought this might have something to do with the nesting which is the equivalent of calling Py_Initialize() twice followed by Py_Finalize() twice.<br>
I went into the C wrapper code for the inner-most customization and commented out the Py_Initialize and Py_Finalize calls and it worked nicely.<br>Further testing showed that I only needed to remove the Py_Finalize call and that calling Py_Initialize twice didn't cause a segfault.<br>
<br>So, now that I think I verified that this is what was causing the segfault, I'd like to ask some questions.<br><br>1)<br>Is calling Py_Initialize twice correct, or will I run into other problems down the road?<br>
<br>2)<br>Another option I have is that I can remove all Py_Initialize / Py_Finalize calls from the individual customizations and just call Py_Initialize once when a user first starts the program.  I am not sure if there is a mechanism to get something called at the end of the user's session with the program though, so is it a problem if I don't call Py_Finalize at the end?<br>
<br>3)<br>Is there a proper way to nest these things?  I imagine not since Py_Finalize doesn't take any arguments.  If I could do...<br>    int session = Py_Initialize()<br>    Py_Finalize(session)<br>But obviously, CPython is not coded that way so it is not supported.<br>
<br>Thanks,<br>~Eric<br>