mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-13 21:13:01 +00:00
make wait_for_server async
This commit is contained in:
@@ -4,8 +4,7 @@
|
|||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import time
|
from tornado import web, gen, ioloop
|
||||||
from tornado import web
|
|
||||||
|
|
||||||
from IPython.html.utils import url_path_join
|
from IPython.html.utils import url_path_join
|
||||||
|
|
||||||
@@ -18,14 +17,16 @@ def random_port():
|
|||||||
return port
|
return port
|
||||||
|
|
||||||
|
|
||||||
|
@gen.coroutine
|
||||||
def wait_for_server(ip, port, timeout=10):
|
def wait_for_server(ip, port, timeout=10):
|
||||||
"""wait for a server to show up at ip:port"""
|
"""wait for a server to show up at ip:port"""
|
||||||
tic = time.time()
|
loop = ioloop.IOLoop.current()
|
||||||
while time.time() - tic < timeout:
|
tic = loop.time()
|
||||||
|
while loop.time() - tic < timeout:
|
||||||
try:
|
try:
|
||||||
socket.create_connection((ip, port))
|
socket.create_connection((ip, port))
|
||||||
except socket.error:
|
except socket.error:
|
||||||
time.sleep(0.1)
|
yield gen.Task(loop.add_timeout, loop.time() + 0.1)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user