Skip to content

Add timeout wait param (Develop) #1700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add timeout wait param
# Conflicts:
#	ml-agents-envs/setup.py
  • Loading branch information
awjuliani committed Feb 12, 2019
commit 33f856eb96396200746fec60f032670056d6e606
14 changes: 8 additions & 6 deletions ml-agents/mlagents/envs/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class UnityEnvironment(object):

def __init__(self, file_name=None, worker_id=0,
base_port=5005, seed=0,
docker_training=False, no_graphics=False):
docker_training=False, no_graphics=False,
timeout_wait=30):
"""
Starts a new unity environment and establishes a connection with the environment.
Notice: Currently communication between Unity and Python takes place over an open socket without authentication.
Expand All @@ -35,8 +36,9 @@ def __init__(self, file_name=None, worker_id=0,
:string file_name: Name of Unity environment binary.
:int base_port: Baseline port number to connect to Unity environment over. worker_id increments over this.
:int worker_id: Number to add to communication port (5005) [0]. Used for asynchronous agent scenarios.
:param docker_training: Informs this class whether the process is being run within a container.
:param no_graphics: Whether to run the Unity simulator in no-graphics mode
:bool docker_training: Informs this class whether the process is being run within a container.
:bool no_graphics: Whether to run the Unity simulator in no-graphics mode
:int timeout_wait: Time (in seconds) to wait for connection from environment.
"""

atexit.register(self._close)
Expand All @@ -45,7 +47,7 @@ def __init__(self, file_name=None, worker_id=0,
self._version_ = "API-6"
self._loaded = False # If true, this means the environment was successfully loaded
self.proc1 = None # The process that is started. If None, no process was started
self.communicator = self.get_communicator(worker_id, base_port)
self.communicator = self.get_communicator(worker_id, base_port, timeout_wait)

# If the environment name is None, a new environment will not be launched
# and the communicator will directly try to connect to an existing unity environment.
Expand Down Expand Up @@ -207,8 +209,8 @@ def executable_launcher(self, file_name, docker_training, no_graphics):
stderr=subprocess.PIPE,
shell=True)

def get_communicator(self, worker_id, base_port):
return RpcCommunicator(worker_id, base_port)
def get_communicator(self, worker_id, base_port, timeout_wait):
return RpcCommunicator(worker_id, base_port, timeout_wait)
# return SocketCommunicator(worker_id, base_port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove dead code


def __str__(self):
Expand Down
5 changes: 3 additions & 2 deletions ml-agents/mlagents/envs/rpc_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def Exchange(self, request, context):


class RpcCommunicator(Communicator):
def __init__(self, worker_id=0, base_port=5005):
def __init__(self, worker_id=0, base_port=5005, timeout_wait=30):
"""
Python side of the grpc communication. Python is the server and Unity the client

Expand All @@ -37,6 +37,7 @@ def __init__(self, worker_id=0, base_port=5005):
"""
self.port = base_port + worker_id
self.worker_id = worker_id
self.timeout_wait = timeout_wait
self.server = None
self.unity_to_external = None
self.is_open = False
Expand Down Expand Up @@ -74,7 +75,7 @@ def check_port(self, port):
s.close()

def initialize(self, inputs: UnityInput) -> UnityOutput:
if not self.unity_to_external.parent_conn.poll(30):
if not self.unity_to_external.parent_conn.poll(self.timeout_wait):
raise UnityTimeOutException(
"The Unity environment took too long to respond. Make sure that :\n"
"\t The environment does not need user interaction to launch\n"
Expand Down