浏览代码

fix on the socket timeout error on windows due to the use of signal.SIGALRM

/develop-generalizationTraining-TrainerController
vincentpierre 7 年前
当前提交
c4745ba7
共有 1 个文件被更改,包括 14 次插入16 次删除
  1. 30
      python/unityagents/environment.py

30
python/unityagents/environment.py


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

正在加载...
取消
保存