Skip to content

fix on the socket timeout error #9

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
Sep 21, 2017
Merged
Changes from all commits
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
30 changes: 14 additions & 16 deletions python/unityagents/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import socket
import subprocess
import signal

from .brain import BrainInfo, BrainParameters
from .exception import UnityEnvironmentException, UnityActionException
Expand Down Expand Up @@ -76,28 +75,27 @@ def __init__(self, file_name, worker_id=0,
except os.error:
self.close()
raise UnityEnvironmentException("Couldn't launch new environment. "
"Provided filename does not match any \environments in {}."
.format(cwd))
"Provided filename does not match any \environments in {}."
.format(cwd))

def timeout_handler():
raise UnityEnvironmentException(
self._socket.settimeout(30)
try:
try:
self._socket.listen(1)
self._conn, _ = self._socket.accept()
self._conn.setblocking(1)
p = self._conn.recv(self._buffer_size).decode('utf-8')
p = json.loads(p)
except socket.timeout as e:
raise UnityEnvironmentException(
"The Unity environment took too long to respond. Make sure {} does not need user interaction to launch "
"and that the Academy and the external Brain(s) scripts are attached to objects in the Scene.".format(
"and that the Academy and the external Brain(s) are attached to objects in the Scene.".format(
str(file_name)))

old_handler = signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(30) # trigger alarm in x seconds
try:
self._socket.listen(1)
self._conn, _ = self._socket.accept()
p = self._conn.recv(self._buffer_size).decode('utf-8')
p = json.loads(p)
except UnityEnvironmentException:
proc1.kill()
self.close()
raise
signal.signal(signal.SIGALRM, old_handler)
signal.alarm(0)


self._data = {}
self._global_done = None
Expand Down