← index #3666Issue #2402
Related · high · value 2.236
QUERY · ISSUE

WiPy/CC3200: usocket.socket.settimeout() not working for socket.getaddrinfo()

openby dmartauzopened 2018-03-09updated 2018-03-16

In issue https://github.com/micropython/micropython/issues/2402 a solution was proposed to make socket.settimeout() working for socket.connect(). It seems to work well.

However it does not work for socket.getaddrinfo() as there seems to be fixed timeout of 19s.

import socket
import ssl
import time

def test():
	start = time.time()
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SEC)
	s = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED, ca_certs='/flash/cert/ca.pem')
	s.settimeout(3)
	try:
		print(socket.getaddrinfo("www.google.com", 443)[0][-1])
	except Exception as e:
		print(e)
	finish = time.time()
	print(finish - start)
	s.close()

EDIT: Looking at the code once again it is obvious that calling settimeout() method of socket instance cannot affect timeout of socket.getaddrinfo(). Anyway is there any way how to modify timeout of this method?

CANDIDATE · ISSUE

WiPy/CC3200: usocket.socket.settimeout() not working?

closedby dmartauzopened 2016-09-07updated 2024-08-28
ports

According to the doc:
Set a timeout on blocking socket operations. The value argument can be a nonnegative floating point number expressing seconds, or None. If a non-zero value is given, subsequent socket operations will raise a timeout exception if the timeout period value has elapsed before the operation has completed. If zero is given, the socket is put in non-blocking mode. If None is given, the socket is put in blocking mode.
http://micropython.org/resources/docs/en/latest/wipy/library/usocket.html#usocket.socket.settimeout

It obviously throws an error:
>>> s.settimeout(5.0) Traceback (most recent call last): File "<stdin>", line 1 SyntaxError: decimal numbers not supported
I was not successful with int parameter. Parameter was accepted, but there is no timeout happening for usocket.socket.accept().

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied