diff --git a/startvms.py b/startvms.py index 937e217..84a5565 100644 --- a/startvms.py +++ b/startvms.py @@ -123,20 +123,17 @@ def wait_for(host, port, timeout=None): else: keep_going = lambda: True while keep_going(): - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.settimeout(1) try: log.debug('Attempting connection to {0}:{1}'.format(host, port)) - s.connect((host, port)) + s = socket.create_connection((host, port), 1) except: log.debug('Connection failed') time.sleep(1) else: log.debug('Connection succeeded') s.shutdown(socket.SHUT_RDWR) - break - finally: s.close() + break else: raise Timeout('Timed out waiting for port {port} on {host}'.format( port=port,