Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-8595: Update urllib, httplib, smtplib docs to warn about global timeout value #27087

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

akulakov
Copy link
Contributor

@akulakov akulakov commented Jul 11, 2021

@akulakov akulakov requested a review from a team as a code owner Jul 11, 2021
@bedevere-bot bedevere-bot added awaiting review docs Documentation in the Doc dir labels Jul 11, 2021
@github-actions
Copy link

github-actions bot commented Aug 26, 2021

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Aug 26, 2021
@MaxwellDupre
Copy link
Contributor

MaxwellDupre commented Mar 17, 2022

http.client (also urllib)
Warning: the global default timeout value is to never time out, which is often
not the desired value for this function.

Better:
Warning: the global default timeout value is set with no timeout, which may
not be the desired value for this function.

smtplib
setting will be used, which is set never to time out). If the timeout expires,
:exc:TimeoutError is raised. The optional source_address parameter allows binding

Better:
setting will be used, which is set with no timeout). If the timeout expires,
:exc:TimeoutError is raised. The optional source_address parameter allows binding

@akulakov
Copy link
Contributor Author

akulakov commented Mar 18, 2022

@MaxwellDupre thanks for reviewing, updated per your comments.

@@ -46,6 +46,9 @@ The module provides the following classes:
The optional *blocksize* parameter sets the buffer size in bytes for
sending a file-like message body.

Warning: the global default timeout value is set with no timeout, which may
Copy link
Member

@JelleZijlstra JelleZijlstra Apr 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a user my next question would be "how do I set this global timeout?". Is there a place in the docs we can link to that explains how to set it?

Also, style nit: I'd remove the "warning:" part.

Copy link
Contributor Author

@akulakov akulakov Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that the global default timeout is set for sockets, - socket.setdefaulttimeout() - and referencing it would imply a recommendation to use it; but it would not be appropriate for sockets to have the same timeout as for http client. Various ideas like adding a similar default timeout along with get/set functions for httplib were discussed but there wasn't a strong agreement on the best approach, and the last messages were from 12 years ago.

For adding a reference to setdfaulttimeout which notes that default value is to never block, we could potentially also note that it's only for reference, and should not be used for setting the timeout, but it seems a bit awkward to reference something that shouldn't be used.

Another idea is to split off a paragraph in socket.setdefaulttimeout() doc with an anchor so that it only describes the value of timeout, but is not a direct link to the function itself. This is a bit better, but the downside is that function is still right above it; and the current doc works well as a single paragraph, and I think splitting it will make it slightly less readable.

I've removed leading 'Warning: '

Copy link
Contributor Author

@akulakov akulakov Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the intent of this change is so that the user says "I don't like this global default value, and there's no direction on how to change it, so the only option is to set it explicitly" - which is probably the best course of action with current design.

Copy link
Contributor

@MaxwellDupre MaxwellDupre left a comment

Docs compile and the info readable.

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Aug 10, 2022
Doc/library/urllib.request.rst Outdated Show resolved Hide resolved
@netlify
Copy link

netlify bot commented Dec 9, 2022

Deploy Preview for python-cpython-preview failed.

Name Link
🔨 Latest commit d1d04bf
🔍 Latest deploy log https://app.netlify.com/sites/python-cpython-preview/deploys/6396a562219b3b00090d67eb

@@ -657,6 +662,10 @@ OpenerDirector Objects
timeout setting will be used). The timeout feature actually works only for
HTTP, HTTPS and FTP connections).

.. note::

The global default timeout value is to never time out, which is often
Copy link
Contributor

@slateny slateny Dec 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this is the original wording and should be updated to the revised wording (as above). Note also this pr which adds a similar note into http.client, so there may be some conflict here if that's merged.

Copy link
Contributor Author

@akulakov akulakov Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, thanks for spotting this - I forgot to pull changes when making a previous update.

The purpose of this PR is to point out what the global default timeout is, and that it's often not a good idea to use that value. The #17843 doesn't clearly point out these 2 things so I think if it's merged, it shouldn't have effect on this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants