Skip to content

Commit

Permalink
Fix segfault due to gym Atari preprocessing module
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoferigo committed Mar 30, 2021
1 parent c71ed2c commit c37d1c7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bindings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c37d1c7

Please sign in to comment.