mirror of
https://github.com/wassname/ray.git
synced 2026-07-02 13:40:51 +08:00
fix test_worker_stats (#7655)
* fix test_worker_stats * fix lint error * fix lint error Co-authored-by: senlin.zsl <senlin.zsl@antfin.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import socket
|
||||
|
||||
import ray
|
||||
|
||||
@@ -234,3 +235,26 @@ def put_object(obj, use_ray_put):
|
||||
return ray.put(obj)
|
||||
else:
|
||||
return _put.remote(obj)
|
||||
|
||||
|
||||
def wait_until_server_available(address,
|
||||
timeout_ms=5000,
|
||||
retry_interval_ms=100):
|
||||
ip_port = address.split(":")
|
||||
ip = ip_port[0]
|
||||
port = int(ip_port[1])
|
||||
time_elapsed = 0
|
||||
start = time.time()
|
||||
while time_elapsed <= timeout_ms:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(1)
|
||||
try:
|
||||
s.connect((ip, port))
|
||||
except Exception:
|
||||
time_elapsed = (time.time() - start) * 1000
|
||||
time.sleep(retry_interval_ms / 1000.0)
|
||||
s.close()
|
||||
continue
|
||||
s.close()
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user