New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
socket timeouts even in blocking mode #49543
Comments
The code below exits with timeout after about 20 secs on Windows + import socket
# address of server routable, but offline
server = "192.168.1.2"
s = socket.socket()
s.setblocking(1)
s.connect((server, 139))
s.close() The output is: Traceback (most recent call last):
File "D:\.env\test.py", line 6, in <module>
s.connect((server, 139))
File "<string>", line 1, in connect
socket.error: (10060, 'Operation timed out') If timeout is set to 1 it exits almost immediately. If timeout is large I use socket to wait for the network service to appear. The target |
Why do you think this is a bug in Python? |
Because documentation doesn't say that Python should timeout after 20 |
You can't use a connect() call for the purpose of waiting for your The "timeout" is due to the network stack being unable to find the |
That's not true: The documentation says "In blocking mode, operations |
After rewriting my reply several times I've noticed my mistake, but it The problem: Analysis: import socket
s = socket.socket()
s.settimeout(12.0)
try:
s.connect(("192.168.1.2", 139))
except socket.timeout:
print "connect timeout" But this one won't: import socket
s = socket.socket()
s.settimeout(120.0)
try:
s.connect(("192.168.1.2", 139))
except socket.timeout:
print "connect timeout" So, for reliable socket programming you should catch both. Solution: |
10060 is a winsock error, and there are many, MANY more of them. Read |
Isn't it a job of crossplatform programming language to abstract from The scope of this bug is not about handling all possible Winsock errors. In addition I believe that new socket.create_connection() function is BTW, I have tested the behaviour on linux - the system timeout on socket socket.error: (110, 'Connection timed out') Note that the error message is different too. That means that to |
It's certainly not Python's job. It's an explicit design goal, and a It might be useful to put a layer on top of the system interfaces,
That's nearly impossible, with respect to specific error conditions. You can easily define an common (but useless) error handling scheme
That's correct. However, you shouldn't look at the error message when |
Yes it is annoying to have to deal with the different OS specific error The issue that prompted this bug report: calling socket.connect() once I have updated the socket module documentation to clarify this a bit in |
Thanks for pointing me to the list of possible network errors. This In the meanwhile I made a script that probes remote service with proper |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: