Skip to content

gh-145912: Add "CPU-bound" and "I/O-bound" to glossary, link existing mentions - #162886

Open
ngoldbaum wants to merge 3 commits into
python:mainfrom
ngoldbaum:glossary-cpu-io-bound
Open

ngoldbaum wants to merge 3 commits into
python:mainfrom
ngoldbaum:glossary-cpu-io-bound

Conversation

@ngoldbaum

@ngoldbaum ngoldbaum commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Adds glossary entries for "CPU-bound" and "I/O-bound" and links to them where the docs use the terms. The existing uses in the docs argues for explicitly and clearly defining these terms IMO.

The linked mentions now use the glossary spelling, replacing e.g. "IO bound" with "I/O-bound".

The second commit fixes a sentence in the asyncio docs that, in a parenthetical gloss, equates blocking code with CPU-bound code. Blocking I/O stalls the event loop too, so it deserves a mention as well.

The multi-threading HOWTO in #162624 will use both terms.

@read-the-docs-community

read-the-docs-community Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Comment thread Doc/glossary.rst Resolved
Co-authored-by: Stan Ulbrych <stan@python.org>

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

INFO: task LGTM blocked for more than 120 seconds.

@itamarst

Copy link
Copy Markdown

Looking...

@itamarst itamarst left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There are two sets of comments:

  • The ones for places where the terms were merely linked. Those could be skipped as out-of-scope (although it's always nice to improve things you're already touching).
  • The ones on the actual definitions, which are more to the point of things I think that should probably be addressed.


This coroutine function is primarily intended to be used for executing
IO-bound functions/methods that would otherwise block the event loop if
:term:`I/O-bound` functions/methods that would otherwise block

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can use it for CPU-bound tasks too?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

But I guess that's change of intention so maybe should be different PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oh but I see it's mentioned later, so it is OK with caveats.

to make I/O-bound functions non-blocking. However, for extension modules
that release the GIL or alternative Python implementations that don't
have one, ``asyncio.to_thread()`` can also be used for CPU-bound functions.
have one, ``asyncio.to_thread()`` can also be used for

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Like free-threading?

operations. This results in better performance for :term:`I/O-bound` use
cases. It also allows off-loading :term:`CPU-bound` work to a thread or
process pool, but that is still limited by the :term:`global
interpreter lock` in CPython.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, could mention free-threading.

Comment thread Doc/glossary.rst
sorting three of them takes about three seconds on one core and can take
as little as one second on three cores. With the
:term:`global interpreter lock`, only one thread runs Python bytecode at
a time, so threads do not speed up CPU-bound Python code. See also

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Free-threading?

Comment thread Doc/glossary.rst

CPU-bound
Describes a task that spends most of its time computing, which keeps a
CPU core busy. Running such tasks :term:`concurrently <concurrency>` on

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"running multiple such tasks"

Comment thread Doc/glossary.rst
by :pep:`492`.

CPU-bound
Describes a task that spends most of its time computing, which keeps a

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"most of its time computing, for example doing mathematical calculations, or string manipulation, or or operating on an in-memory data structure. This keeps CPU core busy."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer we don't add too many examples, it overloads the definitions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think I'll just use a better example than string sorting. I'll give it a think. At one point this talked about compressing in-memory files but that makes the reader think about I/O which is exactly what this entry isn't about.

Comment thread Doc/glossary.rst
CPU core busy. Running such tasks :term:`concurrently <concurrency>` on
one core does not finish the work sooner, because they take turns using
that core, but running them in :term:`parallel <parallelism>` on several
cores can. For example, if sorting a large list takes one second,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorting is maybe not the best example, parallel sorting being non-trivial. Summing a list of integers, maybe?

Comment thread Doc/glossary.rst
another, so running such tasks :term:`concurrently <concurrency>` lets
their waits overlap, even on a single CPU core. For example, three
downloads that each take one second can finish in about one second when
run concurrently, instead of three. See also :term:`CPU-bound`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"instead of three when run sequentially."

@ngoldbaum

Copy link
Copy Markdown
Contributor Author

Thanks Itamar! I think I'll incorporate your suggestions for the glossary and leave the others alone. Lots of docs need updates along these lines and I wanted to keep this PR scoped to just the glossary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants