In Python, I need to wait until a device (which takes ~ 90 seconds to boot) is connected.
I tried a timeout of 120 seconds:
import socket
sock = socket.create_connection(("192.168.254.254", 1234), timeout=120)
# port 1234 for the direct API of the device
but after ~ 20 seconds it fails with:
Trackback (most recent call last):
File "C:\Python38\lib\urllib\request.py", line 1354, in do_open
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Idem, I tried:
from urllib.request import urlopen
req = urlopen("http://192.168.254.254", timeout=120) # the device also has a web interface
but after 21 seconds it fails with the same WinError 10060
.
The device usually has finished boot after 90 seconds, so a timeout of 120 should be enough.
How to do this?
Is 20 seconds a maximum possible timeout on Windows?
Linked question (but not duplicate, it doesn't give the answer): here 20 seconds seems to be mentioned: TCP connection timeout is 20 or 21 seconds on *some* PCs when set to 500ms
This means that you wind up waiting for the underlying TCP operation to fail. This typically takes 20 seconds.
Is there a way to remove this TCP timeout limit of 20 seconds?