aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx
diff options
context:
space:
mode:
authorGravatar Kevin Z. Zhu <86268612+KZhu-ME@users.noreply.github.com> 2021-11-30 09:02:58 -0800
committerGravatar GitHub <noreply@github.com> 2021-11-30 09:02:58 -0800
commit11a5bf5d56b38ed9d09fa12493bd513e5d5bee47 (patch)
treef12987aa07b8cced7a5a5d821c21e9a5598102a5 /Python/pywarpx
parent42737176f91c4dec9a3861f5a0a7b0f3aeaa0440 (diff)
downloadWarpX-11a5bf5d56b38ed9d09fa12493bd513e5d5bee47.tar.gz
WarpX-11a5bf5d56b38ed9d09fa12493bd513e5d5bee47.tar.zst
WarpX-11a5bf5d56b38ed9d09fa12493bd513e5d5bee47.zip
Fix segfault when importing _libwarpx without initializing WarpX (#2580)
* Added check for if warpx was initialized when calling finalize * Renamed to be warpx_initialized * Fixed reference to global variable Co-authored-by: Peter Scherpelz <31747262+peterscherpelz@users.noreply.github.com> * Changed global variable to member of libwarpx * Fixed syntax errors * Remove custom arg from argv to avoid parmparse error Co-authored-by: Peter Scherpelz <31747262+peterscherpelz@users.noreply.github.com>
Diffstat (limited to 'Python/pywarpx')
-rwxr-xr-xPython/pywarpx/_libwarpx.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index 5cfe9bbaa..e32dc239d 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -87,6 +87,9 @@ except OSError as e:
print("Failed to load the libwarpx shared object library")
raise
+# track whether libwarpx has been initialized
+libwarpx.initialized = False
+
# WarpX can be compiled using either double or float
libwarpx.warpx_Real_size.restype = ctypes.c_int
libwarpx.warpx_ParticleReal_size.restype = ctypes.c_int
@@ -323,6 +326,8 @@ def initialize(argv=None, mpi_comm=None):
libwarpx.warpx_CheckGriddingForRZSpectral()
libwarpx.warpx_init()
+ libwarpx.initialized = True
+
@atexit.register
def finalize(finalize_mpi=1):
@@ -332,8 +337,9 @@ def finalize(finalize_mpi=1):
the end of your script.
'''
- libwarpx.warpx_finalize()
- libwarpx.amrex_finalize(finalize_mpi)
+ if libwarpx.initialized:
+ libwarpx.warpx_finalize()
+ libwarpx.amrex_finalize(finalize_mpi)
def evolve(num_steps=-1):