Hi, 2014-04-03 11:34 GMT+02:00 Jonathan Slenders <[email protected]>: > First he proposed to wrap create_connection into wait_for with a timeout=1 > parameter, but that would leave the file descriptor open that was created in > BaseEventLoop.create_connection(). Therefore he proposes to create the > socket ourself, using sock_connect , and if that fails due to a timeout, > call sock.close manually.
When you use wait_for(), the coroutine gets a CancelledError and so can cleanup its data (close the socket). If create_connection() doesn't close the socket on error, it's a bug. Please open an issue. > How is it possible that loop.create_connection blocks? The slowest part is probably the DNS resolution. By default, getaddrinfo() is called in a thread. > Doesn't it just fail after a while if the host is not reachable? Network operations can be slow, but create_connection() should not "block", the coroutine should be running in background, as any "async" task. It would help to identify exactly which Python line hangs. Victor
