Skip to content

Commit

Permalink
Remove Python 2 compatibility in VectorEnv (openai#2034)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandeleu committed Sep 11, 2020
1 parent d920ce2 commit 49d0f17
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
7 changes: 1 addition & 6 deletions gym/vector/async_vector_env.py
Expand Up @@ -68,12 +68,7 @@ class AsyncVectorEnv(VectorEnv):
"""
def __init__(self, env_fns, observation_space=None, action_space=None,
shared_memory=True, copy=True, context=None, daemon=True, worker=None):
try:
ctx = mp.get_context(context)
except AttributeError:
logger.warn('Context switching for `multiprocessing` is not '
'available in Python 2. Using the default context.')
ctx = mp
ctx = mp.get_context(context)
self.env_fns = env_fns
self.shared_memory = shared_memory
self.copy = copy
Expand Down
6 changes: 1 addition & 5 deletions gym/vector/tests/test_shared_memory.py
@@ -1,5 +1,4 @@
import pytest
import sys
import numpy as np

import multiprocessing as mp
Expand All @@ -14,7 +13,6 @@
from gym.vector.utils.shared_memory import (create_shared_memory,
read_from_shared_memory, write_to_shared_memory)

is_python_2 = (sys.version_info < (3, 0))

expected_types = [
Array('d', 1), Array('f', 1), Array('f', 3), Array('f', 4), Array('B', 1), Array('B', 32 * 32 * 3),
Expand All @@ -33,9 +31,7 @@
@pytest.mark.parametrize('n', [1, 8])
@pytest.mark.parametrize('space,expected_type', list(zip(spaces, expected_types)),
ids=[space.__class__.__name__ for space in spaces])
@pytest.mark.parametrize('ctx', [None,
pytest.param('fork', marks=pytest.mark.skipif(is_python_2, reason='Requires Python 3')),
pytest.param('spawn', marks=pytest.mark.skipif(is_python_2, reason='Requires Python 3'))],
@pytest.mark.parametrize('ctx', [None, 'fork', 'spawn'],
ids=['default', 'fork', 'spawn'])
def test_create_shared_memory(space, expected_type, n, ctx):
def assert_nested_type(lhs, rhs, n):
Expand Down

0 comments on commit 49d0f17

Please sign in to comment.