|
|
|
|
|
|
import os |
|
|
|
import socket |
|
|
|
import subprocess |
|
|
|
import signal |
|
|
|
|
|
|
|
from .brain import BrainInfo, BrainParameters |
|
|
|
from .exception import UnityEnvironmentException, UnityActionException |
|
|
|
|
|
|
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.settimeout(30) |
|
|
|
p = self._conn.recv(self._buffer_size).decode('utf-8') |
|
|
|
p = json.loads(p) |
|
|
|
except socket.timeout as e: |
|
|
|
raise UnityEnvironmentException( |
|
|
|
"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( |
|
|
|
|
|
|
|
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) |
|
|
|
signal.signal(signal.SIGALRM, old_handler) |
|
|
|
signal.alarm(0) |
|
|
|
|
|
|
|
|
|
|
|
self._data = {} |
|
|
|
self._global_done = None |
|
|
|