python / cpython

The Python programming language
https://www.python.org
Other
62.76k stars 30.08k forks source link

HOWTO for socket programming and select documentation contradict #89945

Open AlexWaygood opened 2 years ago

AlexWaygood commented 2 years ago
BPO 45787
Nosy @giampaolo, @AlexWaygood

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: ```python assignee = None closed_at = None created_at = labels = ['3.11', 'type-bug', '3.9', '3.10', 'docs'] title = 'HOWTO for socket programming and select documentation contradict' updated_at = user = 'https://github.com/AlexWaygood' ``` bugs.python.org fields: ```python activity = actor = 'AlexWaygood' assignee = 'docs@python' closed = False closed_date = None closer = None components = ['Documentation'] creation = creator = 'AlexWaygood' dependencies = [] files = [] hgrepos = [] issue_num = 45787 keywords = [] message_count = 1.0 messages = ['406167'] nosy_count = 4.0 nosy_names = ['giampaolo.rodola', 'neologix', 'docs@python', 'AlexWaygood'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue45787' versions = ['Python 3.9', 'Python 3.10', 'Python 3.11'] ```

AlexWaygood commented 2 years ago

The HOWTO for socket programming in Python (https://docs.python.org/3/howto/sockets.html#non-blocking sockets) includes the following lines (using triple-quotes here to indicate multiline quotes from the docs):

""" The major mechanical difference [between blocking and non-blocking sockets] is that [for non-blocking sockets] send, recv, connect and accept can return without having done anything. You have (of course) a number of choices. You can check return code and error codes and generally drive yourself crazy. If you don’t believe me, try it sometime. Your app will grow large, buggy and suck CPU. So let’s skip the brain-dead solutions and do it right.

Use select. """

However, if you go to the documentation for the select module (https://docs.python.org/3/library/select html), it pointedly tells you at the top *not* to do exactly what the socket HOWTO tells you to do:

""" Note The selectors module allows high-level and efficient I/O multiplexing, built upon the select module primitives. Users are encouraged to use the selectors module instead, unless they want precise control over the OS-level primitives used. """