-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiple initialize/finalize? #10
Comments
There is an issue, when calling first forpy_finalize and forpy_initialize afterwards and it is related to numpy. By default forpy imports numpy in forpy_initialize. Numpy has a problem when it is re-initialized and crashes. (It should work when you use forpy_initialize(use_numpy=.false.)) See also this Python C API related discussion on Stackoverflow: https://stackoverflow.com/questions/7676314/py-initialize-py-finalize-not-working-twice-with-numpy |
How could I solve this problem?? |
I would suggest to initialize forpy as early as possible in your (main) program and finalize only at the very end of the main program, e. g.: program my_program
use forpy_mod
implicit none
integer :: ierror
ierror = forpy_initialize()
! ....
! do stuff
! ...
call forpy_finalize
end program Do not use forpy_initialize/forpy_finalize pairs in loops or subroutines that you call more than once. Regarding parallelism: Multithreading (e. g. with OpenMP) is problematic, since a thread has to hold the Python GIL (Global interpreter lock) when doing any Python stuff. There are Python C API functions to deal with that but there is no interface for them in forpy (yet). See also: |
Is it possible to have multiple initialize/finalize statements?
It would be nice to confine forpy to given regions.
The text was updated successfully, but these errors were encountered: