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

gh-124210: Add introduction to docs for threading module #127046

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

Conversation

donBarbos
Copy link
Contributor

@donBarbos donBarbos commented Nov 20, 2024

I chose to take courage and add not only a usage example but also an introduction to the documentation.
I was inspired by the documentation at https://docs.python.org/3/library/multiprocessing.html
This page also have introduction before basic example


📚 Documentation preview 📚: https://cpython-previews--127046.org.readthedocs.build/en/127046/library/threading.html#introduction

@donBarbos
Copy link
Contributor Author

@merwok could you check the changes of this PR?

@ZeroIntensity ZeroIntensity self-requested a review January 10, 2025 18:28
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Sorry about the delay on reviews!

units of a process) concurrently within a single process. It allows for the
creation and management of threads, making it possible to execute tasks in
parallel, sharing memory space. Threads are particularly useful when tasks are
I/O-bound, such as reading from or writing to files, or making network requests,
Copy link
Member

Choose a reason for hiding this comment

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

This caught me off guard. Typically, threads are for speeding up CPU bound operations, and something like asyncio is for I/O bound tasks. Threads being more efficient for I/O bound tasks is really only because of the GIL, but we're trying to get rid of that anyway.

Doc/library/threading.rst Outdated Show resolved Hide resolved
bypass the :term:`Global Interpreter Lock <global interpreter lock>`, the
threading module operates within a single process, meaning that all threads
share the same memory space. However, the GIL limits the performance gains of
threading when it comes to CPU-bound tasks, as only one thread can execute
Copy link
Member

Choose a reason for hiding this comment

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

Ah, here we are about CPU bound tasks. I think we should mention the experimental free-threaded builds here.

Doc/library/threading.rst Outdated Show resolved Hide resolved
# Wait for all threads to finish
for t in threads:
t.join()

This module constructs higher-level threading interfaces on top of the lower
Copy link
Member

Choose a reason for hiding this comment

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

I think it looks kind of weird having all this technical information below the introduction. This, and the parts below it down to the note about WASI compatibility, should ideally go before the introduction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked at multiprocessing.rst as a reference and it's in the same order:

Introduction
------------
Common info about module

   python code example

or you mean information about This module constructs higher-level threading interfaces ... needs to be moved before Introduction?

Copy link
Member

Choose a reason for hiding this comment

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

or you mean information about This module constructs higher-level threading interfaces ... needs to be moved before Introduction?

Yeah, as well as the stuff about compatibility, versionadded, and whatnot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

donBarbos and others added 3 commits January 12, 2025 16:54
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Doc/library/threading.rst Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants