浏览代码

Linux: reuse ports faster (#4036)

* [WIP] Reuse ports on linux

* Check socket

* platform dependent behavior

* Added a comment

* Update ml-agents-envs/mlagents_envs/rpc_communicator.py

Co-authored-by: Jonathan Harper <jharper+moar@unity3d.com>

Co-authored-by: Jonathan Harper <jharper+moar@unity3d.com>
/MLA-1734-demo-provider
GitHub 5 年前
当前提交
6d4d6bf3
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5
      ml-agents-envs/mlagents_envs/rpc_communicator.py

5
ml-agents-envs/mlagents_envs/rpc_communicator.py


import grpc
from typing import Optional
from sys import platform
import socket
from multiprocessing import Pipe
from concurrent.futures import ThreadPoolExecutor

Attempts to bind to the requested communicator port, checking if it is already in use.
"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if platform == "linux" or platform == "linux2":
# On linux, the port remains unusable for TIME_WAIT=60 seconds after closing
# SO_REUSEADDR frees the port right after closing the environment
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.bind(("localhost", port))
except socket.error:

正在加载...
取消
保存