I'm learning to use sockets in python and something weird is happening. 
I call socket.connect in a try block, and typically it either completes and I have a new socket connection, or it raises the exception.  Sometimes, however, it just hangs.
I don't understand why sometimes it returns (even without connecting!) and other times it just hangs.  What makes it hang?
I am using blocking sockets (non-blocking don't seem to work for connect...), so I've added a timeout, but I'd prefer connect to finish without needing to timeout.
Perhaps, when it doesn't hang, it receives a response that tells it the requested ip/port is not available, and when it does hang there is just no response from the other end?
I'm on OSX10.8 using python2.7
Firewall may be the explanation behind this unexpected response. Rather than supposing the remote firewall accepts connection, using timeout is the best option. Since, making a connection is a swift process and within a network, it won't take longer time. So, give a proper timeout so that you can tell that the host is either down or dropping packets.
Python socket.connect hangs sometimes