Skip to content

Commit acc08e3

Browse files
author
Jonathan Harper
committed
Addressing review feedback
1 parent 52a7bc9 commit acc08e3

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

com.unity.ml-agents/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414
- Renamed 'Generalization' feature to 'Environment Parameter Randomization'.
1515
- Fixed an issue where specifying `vis_encode_type` was required only for SAC. (#3677)
1616
- The way that UnityEnvironment decides the port was changed. If no port is specified, the behavior will depend on the `file_name` parameter. If it is `None`, 5004 (the editor port) will be used; otherwise 5005 (the base environment port) will be used.
17-
- Shortened the timeout while waiting for the environment executable to close. (#3679)
17+
- Environment subprocesses now close immediately on timeout or wrong API version. (#3679)
1818

1919
## [0.15.0-preview] - 2020-03-18
2020
### Major Changes

ml-agents-envs/mlagents_envs/environment.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ class UnityEnvironment(BaseEnv):
7272
# Command line argument used to pass the port to the executable environment.
7373
PORT_COMMAND_LINE_ARG = "--mlagents-port"
7474

75-
# Seconds to wait for the environment to cleanly shutdown.
76-
SHUTDOWN_WAIT = 5
77-
7875
def __init__(
7976
self,
8077
file_name: Optional[str] = None,
@@ -156,12 +153,12 @@ def __init__(
156153
aca_output = self.send_academy_parameters(rl_init_parameters_in)
157154
aca_params = aca_output.rl_initialization_output
158155
except UnityTimeOutException:
159-
self._close()
156+
self._close(0)
160157
raise
161158

162159
unity_communicator_version = aca_params.communication_version
163160
if unity_communicator_version != UnityEnvironment.API_VERSION:
164-
self._close()
161+
self._close(0)
165162
raise UnityEnvironmentException(
166163
f"The communication API version is not compatible between Unity and python. "
167164
f"Python API: {UnityEnvironment.API_VERSION}, Unity API: {unity_communicator_version}.\n "
@@ -242,7 +239,7 @@ def validate_environment_path(env_path: str) -> Optional[str]:
242239
def executable_launcher(self, file_name, docker_training, no_graphics, args):
243240
launch_string = self.validate_environment_path(file_name)
244241
if launch_string is None:
245-
self._close()
242+
self._close(0)
246243
raise UnityEnvironmentException(
247244
f"Couldn't launch the {file_name} environment. Provided filename does not match any environments."
248245
)
@@ -447,13 +444,15 @@ def close(self):
447444
else:
448445
raise UnityEnvironmentException("No Unity environment is loaded.")
449446

450-
def _close(self):
447+
def _close(self, timeout: Optional[int] = None) -> None:
448+
if timeout is None:
449+
timeout = self.timeout_wait
451450
self._loaded = False
452451
self.communicator.close()
453452
if self.proc1 is not None:
454453
# Wait a bit for the process to shutdown, but kill it if it takes too long
455454
try:
456-
self.proc1.wait(timeout=self.SHUTDOWN_WAIT)
455+
self.proc1.wait(timeout=timeout)
457456
signal_name = self.returncode_to_signal_name(self.proc1.returncode)
458457
signal_name = f" ({signal_name})" if signal_name else ""
459458
return_info = f"Environment shut down with return code {self.proc1.returncode}{signal_name}."

0 commit comments

Comments
 (0)