Skip to content

Commit

Permalink
Try to avoid Fatal Python error Illegal instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Jan 24, 2024
1 parent bf53047 commit 5e6f29b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/fluidfft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"""

from importlib import import_module as _import_module
import importlib
import subprocess
import sys

from fluiddyn.util.mpi import printby0

Expand Down Expand Up @@ -114,15 +116,26 @@ def import_fft_class(method, raise_import_error=True):
"not method.startswith('fluidfft.')\nmethod = {}".format(method)
)

if any(method.endswith(postfix) for postfix in ("pfft", "p3dfft")):
# for few methods, try before real import because importing can lead to
# a fatal error (Illegal instruction)
try:
subprocess.check_call([sys.executable, "-c", "import " + method])
except subprocess.CalledProcessError as error:
if raise_import_error:
raise ImportError(method) from error

printby0("ImportError:", method)
return None

try:
mod = _import_module(method)
mod = importlib.import_module(method)
except ImportError:
if raise_import_error:
raise ImportError(method)
raise

else:
printby0("ImportError:", method)
return None
printby0("ImportError:", method)
return None

return mod.FFTclass

Expand Down

0 comments on commit 5e6f29b

Please sign in to comment.