s/multiuser/jupyterhub

This commit is contained in:
MinRK
2014-08-19 17:23:57 -07:00
parent 0f4537e473
commit c7acaec239
17 changed files with 12 additions and 44 deletions

30
jupyterhub/utils.py Normal file
View File

@@ -0,0 +1,30 @@
"""Miscellaneous utilities"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import socket
import time
from IPython.html.utils import url_path_join
def random_port():
"""get a single random port"""
sock = socket.socket()
sock.bind(('', 0))
port = sock.getsockname()[1]
sock.close()
return port
def wait_for_server(ip, port, timeout=10):
"""wait for a server to show up at ip:port"""
tic = time.time()
while time.time() - tic < timeout:
try:
socket.create_connection((ip, port))
except socket.error:
time.sleep(0.1)
else:
break