File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -237,12 +237,30 @@ Methods
237237
238238.. method :: socket.settimeout(value)
239239
240+ **Note **: Not every port supports this method, see below.
241+
240242 Set a timeout on blocking socket operations. The value argument can be a nonnegative floating
241243 point number expressing seconds, or None. If a non-zero value is given, subsequent socket operations
242244 will raise an `OSError ` exception if the timeout period value has elapsed before the operation has
243245 completed. If zero is given, the socket is put in non-blocking mode. If None is given, the socket
244246 is put in blocking mode.
245247
248+ Not every `MicroPython port ` supports this method. A more portable and
249+ generic solution is to use `uselect.poll ` object. This allows to wait on
250+ multiple objects at the same time (and not just on sockets, but on generic
251+ stream objects which support polling). Example::
252+
253+ # Instead of:
254+ s.settimeout(1.0) # time in seconds
255+ s.read(10) # may timeout
256+
257+ # Use:
258+ poller = uselect.poll()
259+ poller.register(s, uselect.POLLIN)
260+ res = poller.poll(1000) # time in milliseconds
261+ if not res:
262+ # s is still not ready for input, i.e. operation timed out
263+
246264 .. admonition :: Difference to CPython
247265 :class: attention
248266
You can’t perform that action at this time.
0 commit comments