Skip to content

Commit b8e0d77

Browse files
kenjitoyamacopybara-github
authored andcommitted
Remove socket.error handling.
We have no code that raises `socket.error` anymore and we should remove this error handling as it's confusing and irrelevant. This is a relic from the time AndroidEnv used to interact with the Android Emulator via telnet. PiperOrigin-RevId: 730579911
1 parent 9a0eb91 commit b8e0d77

File tree

3 files changed

+2
-30
lines changed

3 files changed

+2
-30
lines changed

android_env/components/action_fns.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
"""Functions to convert actions between different components' formats."""
1717

18-
import socket
19-
2018
from absl import logging
2119
from android_env.components import action_type as action_type_lib
2220
from android_env.components import errors
@@ -61,7 +59,7 @@ def send_action_to_simulator(
6159
simulator.send_key(action['keycode'].item(0), event_type='keyup')
6260
case action_type_lib.ActionType.KEYPRESS:
6361
simulator.send_key(action['keycode'].item(0), event_type='keypress')
64-
except (socket.error, errors.SendActionError):
62+
except errors.SendActionError:
6563
logging.exception('Unable to execute action: %r', action)
6664
return False
6765

android_env/components/action_fns_test.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import socket
1716
from unittest import mock
1817

1918
from absl.testing import absltest
@@ -45,30 +44,6 @@ def test_send_action_to_simulator_missing_action_type(self):
4544
1,
4645
)
4746

48-
def test_send_action_to_simulator_socket_error(self):
49-
"""Returns `False` if the simulator raises a socket error."""
50-
51-
# Arrange.
52-
simulator = mock.create_autospec(base_simulator.BaseSimulator)
53-
simulator.send_touch.side_effect = socket.error('not today')
54-
action = {
55-
'action_type': action_type_lib.ActionType.TOUCH,
56-
'touch_position': np.array([0.3, 0.5], np.float32),
57-
}
58-
59-
# Act.
60-
output = action_fns.send_action_to_simulator(
61-
action,
62-
simulator,
63-
800,
64-
600,
65-
1,
66-
)
67-
68-
# Assert.
69-
self.assertFalse(output)
70-
simulator.send_touch.assert_called_once()
71-
7247
def test_send_action_to_simulator_sendactionerror(self):
7348
"""Returns `False` if the simulator raises a SendActionError."""
7449

android_env/components/coordinator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"""Coordinator handles interaction between internal components of AndroidEnv."""
1717

1818
import copy
19-
import socket
2019
import time
2120
from typing import Any
2221

@@ -238,7 +237,7 @@ def rl_step(self, agent_action: dict[str, np.ndarray]) -> dm_env.TimeStep:
238237
# Get data from the simulator.
239238
try:
240239
simulator_signals = self._gather_simulator_signals()
241-
except (errors.ReadObservationError, socket.error):
240+
except errors.ReadObservationError:
242241
logging.exception('Unable to fetch observation. Restarting simulator.')
243242
self._stats['relaunch_count_fetch_observation'] += 1
244243
self._simulator_healthy = False

0 commit comments

Comments
 (0)