From ba402afac8d858b8f985fe71e5af8434fb5d49db Mon Sep 17 00:00:00 2001 From: Diego Ferigo Date: Tue, 30 Mar 2021 11:09:37 +0200 Subject: [PATCH] Fix segfault due to gym Atari preprocessing module --- bindings/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bindings/__init__.py b/bindings/__init__.py index 9f9819824..812f6fadf 100644 --- a/bindings/__init__.py +++ b/bindings/__init__.py @@ -74,6 +74,18 @@ def preload_tensorflow_shared_libraries() -> None: ctypes.CDLL(str(lib)) +def pre_import_gym() -> None: + + # Check if gym is installed + import importlib.util + spec = importlib.util.find_spec("gym") + + if spec is None: + return + + import gym + + def import_gazebo() -> None: # Check the the module was never loaded by someone else @@ -85,6 +97,11 @@ def import_gazebo() -> None: if os.environ.get("SCENARIO_DISABLE_TENSORFLOW_PRELOAD") != "1": preload_tensorflow_shared_libraries() + # Import gym before scenario.bindings.gazebo. Similarly to tensorflow, also gym + # includes a module that imports protobuf, producing a similar segfault. + if os.environ.get("SCENARIO_DISABLE_GYM_PREIMPORT") != "1": + pre_import_gym() + # Import SWIG bindings # See https://github.com/robotology/gym-ignition/issues/7 # https://stackoverflow.com/a/45473441/12150968