summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-10-31 00:28:28 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-10-31 00:28:28 +0200
commitb81fbf938f1bb9cc798a3933476c80c0d9b83992 (patch)
tree8426b54b51ed155ade27a8342f9004652a522c6c
parent4dd523adbbe8852c9e02191d4a67ea6c7aa72aec (diff)
docs/usocket: Document that settimeout() isn't supported by all ports.
And describe an alternative of using uselect.poll().
-rw-r--r--docs/library/usocket.rst18
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/library/usocket.rst b/docs/library/usocket.rst
index 53936505b..fab05b652 100644
--- a/docs/library/usocket.rst
+++ b/docs/library/usocket.rst
@@ -237,12 +237,30 @@ Methods
.. method:: socket.settimeout(value)
+ **Note**: Not every port supports this method, see below.
+
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 an `OSError` 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.
+ Not every `MicroPython port` supports this method. A more portable and
+ generic solution is to use `uselect.poll` object. This allows to wait on
+ multiple objects at the same time (and not just on sockets, but on generic
+ stream objects which support polling). Example::
+
+ # Instead of:
+ s.settimeout(1.0) # time in seconds
+ s.read(10) # may timeout
+
+ # Use:
+ poller = uselect.poll()
+ poller.register(s, uselect.POLLIN)
+ res = poller.poll(1000) # time in milliseconds
+ if not res:
+ # s is still not ready for input, i.e. operation timed out
+
.. admonition:: Difference to CPython
:class: attention