[Numpy-discussion] f2py: sharing F90 module data between modules

Pearu Peterson pearu@cens.ioc...
Tue Feb 12 05:10:53 CST 2008

On Tue, February 12, 2008 7:52 am, Garry Willgoose wrote:
> I have a suite of fortran modules that I want to wrap with f2py
> independently (so they appear to python as seperate imports) but
> where each module has access to another fortran module (which
> contains global data that is shared between the suite of fortran
> modules). I currently compile all the fortran modules, including the
> global data, in a single f2py statement so all the fortran code gets
> imported in a single statement

The source of this issue boils down to


according to which makes your goal unachivable because of how
Python loads shared libraries *by default*, see below.

> I guess the question is there any way that I can get fm3 to be shared
> between fm1 and fm2? The reasons for wanting to do this are because
> I'm developing a plug-in like architecture for environmental
> modelling where the user can develop new fortran modules (suitably
> f2py'ed) that can just be dropped into the module search path but
> still have access to the global data (subject to fortran module
> interfaces, etc).

The link above also gives an hint how to resolve this issue.
Try to use sys.setdlopenflags(...) before importing f2py generated
extension modules and then reset the state using sys.setdlopenflags(0).
for more information how to find proper value for ...


More information about the Numpy-discussion mailing list