ylikx / forpy

Forpy - use Python from Fortran

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Py_finalize and segmentation fault - Running multiple routines

wilsoniain opened this issue · comments

Calling a forpy subroutine multiple times results in a segmentation fault. This happens when the second instance of calling forpy_initialize() occurs.

Based on discussion here: #1
Is this related to requiring multiple interpreters / threading support?

Or, also related to operation of py_finalize?

Bugs and caveats: The destruction of modules and objects in modules is done in random order; this may cause destructors (__del__() methods) to fail when they depend on other objects (even functions) or modules. Dynamically loaded extension modules loaded by Python are not unloaded. Small amounts of memory allocated by the Python interpreter may not be freed (if you find a leak, please report it). Memory tied up in circular references between objects is not freed. Some memory allocated by extension modules may not be freed. Some extensions may not work properly if their initialization routine is called more than once; this can happen if an application calls Py_Initialize() and Py_Finalize() more than once.

Any help appreciated.

Based on the above py_finalize caveat, it seems the best solution is to call py_initialize and py_finalize in from their own individual subroutines. This avoids multiple calls to py_initialize and the resulting segmentation fault.

Hi, the segmentation fault is due to a bug in numpy, finalizing and reinitializing is not possible with numpy. I recommend calling py_finalize once at the end of your program. See #10.