-
Notifications
You must be signed in to change notification settings - Fork 19
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
segmentation fault if AMReX is not initialized #327
Comments
Discovered via this PR: #320 |
It's not surprising that a lot of amrex function won't work without amrex::Initialize called. |
No, but I don't think it should segfault. This is very surprising (bad) behavior for a Python program. Python scripts should never segfault. |
Can amrex be initialized when the module is imported? |
Hm, I am a bit hesitant to add a lot if if amrex initialized checks in pyAMReX. But if you add them upstream then we can just C++ throw and this will (should) propagate as a runtime exception to pyAMReX. |
mpi4py style? Possibly... But there is a lot of runtime stuff people might want to pass to init |
Is it possible to re-init after the first (default) init? |
Yes, for pyAMReX, we added fixes in AMReX that make sure we can finalize and reinit many times in a row in the same process. I always considered import-time side-effects as an anti-pattern in Python. Lines 31 to 32 in c61add4
or this (mpi4py): Lines 19 to 21 in c61add4
I mean this is even confusing to linter tools... I wonder if we can find another solution 🤔 |
An alternative could be to only allow access to pyAMReX functions with a content manager... Something like import amrex.space3d as amr
with amr.Initialized() as amx:
amx.PlotFileData("./tests/projz04000/") |
That might work. |
What would be a good syntax? from amrex.space3d import amr_initialize
with amr_initialize() as amr:
amr.PlotFileData("./tests/projz04000/") |
Maybe something like: from amrex.space3d import AmrContext:
with AmrContext(mpi_comm=None) as amr:
amr.PlotFileData("./tests/projz04000/") or from amrex.space3d import AmrContext:
with AmrContext() as amr:
amr.PlotFileData("./tests/projz04000/") I think calling it |
Sounds good. Other names could be |
The Python interpreter segfaults if a function is called without initializing AMReX:
whereas this works fine:
The text was updated successfully, but these errors were encountered: