[issue23251] mention in time.sleep() docs that it does not block other Python threads
New submission from Akira Li: There is the corresponding StackOverflow question with 60K view "time.sleep — sleeps thread or process?" [1] The documentation patch is attached. [1] http://stackoverflow.com/questions/92928/time-sleep-sleeps-thread-or-process ---------- assignee: docs@python components: Documentation files: docs-time.sleep-other-threads-are-not-blocked.diff keywords: patch messages: 234135 nosy: akira, docs@python priority: normal severity: normal status: open title: mention in time.sleep() docs that it does not block other Python threads type: enhancement versions: Python 3.5 Added file: http://bugs.python.org/file37730/docs-time.sleep-other-threads-are-not-block... _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
R. David Murray added the comment: Can you re-upload the patch without reflowing the paragraph? I think the only thing needed is the addition of the word thread, to mirror the equivalent unix man page phrasing, and I think that's what you've done, but I can't easily tell from the provided patch. ---------- nosy: +r.david.murray _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Martin Panter added the comment: There is also a new sentence about the GIL at the end, but leaving the inbetween lines as they were would verify this ---------- nosy: +vadmium _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Akira Li added the comment: I do not understand. Have you tried to look at the patch in Rietveld? The new content is highlighted in a darker green. It is clearly visible. I've tested on Chromium, Firefox, Safari. If I won't reflow then the first line will be longer than the recommended 80 in devguide:
The maximum line length is 80 characters for normal text, but tables, deeply indented code samples and long links may extend beyond that.
I've set *fill-column* to 80 in emacs. Do you suggest other settings? Anyway, it doesn't affect how the final text is shown in a web browser. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
I guess R. David Murray asked you to make the least minimal change, even it breaks the formatting rules. Paragraph reflow is safe when it's done by the Core Developer but it requires additional check (and probably mercurial conflict errors on merging the change with default branch if the last has changes also). In your case I see no problems though, but the final decision is on R. David Murray On Sat, Jan 17, 2015 at 12:56 AM, Akira Li <report@bugs.python.org> wrote:
Akira Li added the comment:
I do not understand. Have you tried to look at the patch in Rietveld?
The new content is highlighted in a darker green. It is clearly visible. I've tested on Chromium, Firefox, Safari.
If I won't reflow then the first line will be longer than the recommended 80 in devguide:
The maximum line length is 80 characters for normal text, but tables, deeply indented code samples and long links may extend beyond that.
I've set *fill-column* to 80 in emacs. Do you suggest other settings?
Anyway, it doesn't affect how the final text is shown in a web browser.
----------
_______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________ _______________________________________________ docs mailing list docs@python.org https://mail.python.org/mailman/listinfo/docs
-- Thanks, Andrew Svetlov
Martin Panter added the comment: What I have sometimes done in this situation is just break the overly long line into two short lines ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
R. David Murray added the comment: I actually didn't know that reitveld was smart enough to highlight just the text changes in a reflowed paragraph. Nevertheless, for ease of looking at diff in the repository using the hg command (which is not that smart), I prefer to commit doc changes without the reflow, then do the reflow in a separate commit. I don't know if other developers do this or not. I think the patch is fine. ---------- stage: -> commit review versions: +Python 2.7, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Antoine Pitrou added the comment: I think it's superfluous to mention the GIL here, since it has no impact on the function. ---------- nosy: +pitrou _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Akira Li added the comment:
I think it's superfluous to mention the GIL here, since it has no impact on the function.
If GIL is not released then all Python code in other threads is effectively blocked. It is worth mentioning explicitly that it is guaranteed to be released during the sleep. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Antoine Pitrou added the comment:
If GIL is not released then all Python code in other threads is effectively blocked.
But that would be a stupid implementation of sleep(). It is not desirable to clutter the docs with such mentions: most calls to the OS in the stdlib release the GIL. Only if the behaviour was unintuitive (i.e. if it *didn't* release the GIL) would it make sense to document it. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
R. David Murray added the comment: Yes, on consideration I agree with Antoine. That last sentence should be deleted. Otherwise we'd need to mention that the gil was released every place that the gil was released, which would be very redundant. The general rule is that anything that blocks in python releases the GIL, therefore as Antoine says the only time we need to document GIL behavior is when that *doesn't* happen. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Akira Li added the comment:
Only if the behaviour was unintuitive (i.e. if it *didn't* release the GIL) would it make sense to document it.
There is no intuitive interface, not even the nipple. It's all learned. [1]
Yes, on consideration I agree with Antoine. That last sentence should be deleted. Otherwise we'd need to mention that the gil was released every place that the gil was released, which would be very redundant.
Whether or not other places mention it is unrelated to the current issue. Though the documentation should mention it more. Many programmers are convinced that Python threads can't be executed in parallel.
The general rule is that anything that blocks in python releases the GIL, therefore as Antoine says the only time we need to document GIL behavior is when that *doesn't* happen.
The reader of Python documentation is intelegent but not all-knowing. "Blocking" is the first and only job for time.sleep() function. GIL "blocks" Python code. You can't understand what time.sleep does without knowing what happens to GIL. Ask yourself who and why reads the time.sleep() documentation (novice and/or exprerienced Python user). Put yourself into the mind of the reader. [1] http://www.greenend.org.uk/rjk/misc/nipple.html ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Antoine Pitrou added the comment: Please let's stop it. Mentioning the GIL in every place in the documentation will only make people more worried and confused about something they shouldn't be confused or worried about. If you think some docs should discuss the GIL and its effect on running threads then I suggest writing a separate document (a HOWTO for example, like the Unicode HOWTO). ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Andrew Svetlov added the comment: I'm with Antoine. Yes, GIL is extremely important but please don't put GIL mentions everywhere. On Sun, Jan 18, 2015 at 4:39 PM, Antoine Pitrou <report@bugs.python.org> wrote:
Antoine Pitrou added the comment:
Please let's stop it. Mentioning the GIL in every place in the documentation will only make people more worried and confused about something they shouldn't be confused or worried about.
If you think some docs should discuss the GIL and its effect on running threads then I suggest writing a separate document (a HOWTO for example, like the Unicode HOWTO).
----------
_______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Georg Brandl added the comment: Agreed. "of the current thread" is a good addition. The sleep() docs are already longer than I would like. ---------- nosy: +georg.brandl _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Akira Li added the comment: I've removed mentioning of GIL and uploaded a new patch. ---------- Added file: http://bugs.python.org/file37850/docs-time.sleep-other-threads-are-not-block... _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Roundup Robot added the comment: New changeset 55ad65c4f9e2 by R David Murray in branch '3.4': #23251: Note that time.sleep affects the calling thread only. https://hg.python.org/cpython/rev/55ad65c4f9e2 New changeset 5e01c68cabbf by R David Murray in branch '2.7': #23251: note that time.sleep affects the current thread only. https://hg.python.org/cpython/rev/5e01c68cabbf New changeset 5db28a3199b2 by R David Murray in branch '2.7': #23251: Reflow paragraph. https://hg.python.org/cpython/rev/5db28a3199b2 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
R. David Murray added the comment: Oops, typoed the issue number. New changeset 3a9b1e5fe179 by R David Murray in branch '3.4': #23215: reflow paragraph. https://hg.python.org/cpython/rev/3a9b1e5fe179 New changeset 52a06812d5da by R David Murray in branch 'default': Merge: #23215: note that time.sleep affects the current thread only. https://hg.python.org/cpython/rev/52a06812d5da ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
R. David Murray added the comment: Thanks, Akira, but I did not use your patch, since it still had the paragraph reflow in it. ---------- resolution: -> fixed stage: commit review -> resolved _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
Changes by Berker Peksag <berker.peksag@gmail.com>: ---------- status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23251> _______________________________________
participants (9)
-
Akira Li
-
Andrew Svetlov
-
Andrew Svetlov
-
Antoine Pitrou
-
Berker Peksag
-
Georg Brandl
-
Martin Panter
-
R. David Murray
-
Roundup Robot