import socket
import time


def wait_for_connect(host, port, tries=50):
	"""
	Try to open up a socket to host:port -- if something is listening there,
	we'll take that to mean the process is up and running.  Will retry every
	tenth of a second, up to the retry limit.
	"""
	while tries > 0:
		try:
			tries -= 1
			s = socket.socket()
			s.connect((host, port))
			return True
		except socket.error:
			time.sleep(0.1)
	return False