mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-19 13:32:03 +00:00
Remove Python 2 compatibility in VectorEnv (#2034)
This commit is contained in:
@@ -68,12 +68,7 @@ class AsyncVectorEnv(VectorEnv):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, env_fns, observation_space=None, action_space=None,
|
def __init__(self, env_fns, observation_space=None, action_space=None,
|
||||||
shared_memory=True, copy=True, context=None, daemon=True, worker=None):
|
shared_memory=True, copy=True, context=None, daemon=True, worker=None):
|
||||||
try:
|
|
||||||
ctx = mp.get_context(context)
|
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
|
|
||||||
self.env_fns = env_fns
|
self.env_fns = env_fns
|
||||||
self.shared_memory = shared_memory
|
self.shared_memory = shared_memory
|
||||||
self.copy = copy
|
self.copy = copy
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import sys
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
@@ -14,7 +13,6 @@ from gym.vector.tests.utils import spaces
|
|||||||
from gym.vector.utils.shared_memory import (create_shared_memory,
|
from gym.vector.utils.shared_memory import (create_shared_memory,
|
||||||
read_from_shared_memory, write_to_shared_memory)
|
read_from_shared_memory, write_to_shared_memory)
|
||||||
|
|
||||||
is_python_2 = (sys.version_info < (3, 0))
|
|
||||||
|
|
||||||
expected_types = [
|
expected_types = [
|
||||||
Array('d', 1), Array('f', 1), Array('f', 3), Array('f', 4), Array('B', 1), Array('B', 32 * 32 * 3),
|
Array('d', 1), Array('f', 1), Array('f', 3), Array('f', 4), Array('B', 1), Array('B', 32 * 32 * 3),
|
||||||
@@ -33,9 +31,7 @@ expected_types = [
|
|||||||
@pytest.mark.parametrize('n', [1, 8])
|
@pytest.mark.parametrize('n', [1, 8])
|
||||||
@pytest.mark.parametrize('space,expected_type', list(zip(spaces, expected_types)),
|
@pytest.mark.parametrize('space,expected_type', list(zip(spaces, expected_types)),
|
||||||
ids=[space.__class__.__name__ for space in spaces])
|
ids=[space.__class__.__name__ for space in spaces])
|
||||||
@pytest.mark.parametrize('ctx', [None,
|
@pytest.mark.parametrize('ctx', [None, 'fork', 'spawn'],
|
||||||
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'))],
|
|
||||||
ids=['default', 'fork', 'spawn'])
|
ids=['default', 'fork', 'spawn'])
|
||||||
def test_create_shared_memory(space, expected_type, n, ctx):
|
def test_create_shared_memory(space, expected_type, n, ctx):
|
||||||
def assert_nested_type(lhs, rhs, n):
|
def assert_nested_type(lhs, rhs, n):
|
||||||
|
Reference in New Issue
Block a user